Python Metaprogramming

Learning PathSkills: Python, Metaclasses, Descriptors, Dynamic Code Execution, exec(), eval(), Code Evaluation, Python Internals

A person bringing object boxes to a metaclass machine

Elevate your Python skills by mastering metaprogramming. Explore metaclasses, descriptors, and dynamic code execution using exec() and eval(). Ideal for advanced users wanting to harness Python’s dynamic capabilities.

Python Metaprogramming

Learning Path ⋅ 4 Resources

Title image for Metaclasses in Python (Python Metaclasses and Metaprogramming)

Course

Metaclasses in Python

Metaclasses are an important but mysterious behind-the-scenes mechanism for instantiating classes in Python. In this video course, you'll learn how Python's metaclasses work in object-oriented programming.

Title image for Python Descriptors: An Introduction (Python Descriptors: An Introduction)

Tutorial

Python Descriptors: An Introduction

Learn what Python descriptors are and how they're used in Python's internals. You'll learn about the descriptor protocol and how the lookup chain works when you access an attribute. You'll also see a few practical examples where Python descriptors can come in handy.

Title image for Python's exec(): Execute Dynamically Generated Code (Python's exec(): Execute Dynamically Generated Code)

Tutorial

Python's exec(): Execute Dynamically Generated Code

Learn how to use Python's built-in exec() function to execute code that comes as either a string or a compiled code object.

Title image for Evaluate Expressions Dynamically With Python eval() (Python's eval(): Evaluating Expressions Dynamically)

Course

Evaluate Expressions Dynamically With Python eval()

Learn how Python's eval() works and how to use it effectively in your programs. Additionally, you'll learn how to minimize the security risks associated to the use of eval().

Got feedback on this learning path?

Looking for real-time conversation? Visit the Real Python Community Chat or join the next “Office Hours” Live Q&A Session. Happy Pythoning!

« Browse All Learning Paths