Python Metaprogramming

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

A person bringing object boxes to a metaclass machine

In this learning path, you’ll explore Python’s metaprogramming capabilities. You’ll start with metaclasses and descriptors to understand how Python creates and manages classes, then learn to execute and evaluate code dynamically using exec() and eval().

Python Metaprogramming

Learning Path ⋅ 4 Resources

Classes and Protocols

Metaclasses and descriptors let you customize how Python creates classes and accesses attributes. You’ll learn how these mechanisms work and when to use them.

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 (Python Descriptors: An Introduction)

Course

Python Descriptors

Learn what Python descriptors are, how the descriptor protocol works, and when descriptors are useful—with practical, hands-on examples.

Dynamic Code Execution

Python can execute and evaluate code at runtime using exec() and eval(). You’ll learn how these built-in functions work and what to watch out for when using them.

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().

Congratulations on completing this learning path! You’ve explored Python’s metaprogramming tools, from metaclasses and descriptors to dynamic code execution.

Continue your advanced Python journey with the next learning path:

Learning Path

Network Programming and Security

4 Resources ⋅ Skills: CRUD Operations, REST APIs, HTTPS, Socket Programming, Network Security, Web Services

You might also be interested in these related learning paths:

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