Description
Kyle Knapp - Dynamic Class Generation in Python [EuroPython 2016] [18 July 2016] [Bilbao, Euskadi, Spain] (https://ep2016.europython.eu//conference/talks/dynamic-class-generation-in-python)
This talk is about dynamic class generation in python: the practice of writing code that generates classes and their functionality at runtime. It will use boto3, the AWS SDK for Python, as a basis to dive into the basics, the benefits, and the drawbacks to dynamically generating classes.
This talk is about the concept of dynamic class generation in python. The whole idea is writing code that generates classes and their functionality at runtime. You now may be asking yourself, “That sounds like a neat trick. Why would I ever generate my classes at runtime?” Here are a few reasons why:
- It can decrease the physical size of your code.
- It can improve the workflow in adding new functionality.
- It can improve reliability of your code.
One example where the power of this concept has really been leveraged is in boto3, the AWS SDK for Python. Dynamic class generation has allowed boto3 to become heavily data driven such that most of its classes and methods are generated based off JSON models representing aspects of an AWS service’s API. For example, to add support for a new AWS service API in boto3, just plop in a JSON file into the library with no additional Python code required.
Using lessons and techniques drawn from developing boto3, this talk will dive into the following topics related to dynamic class generation:
- The basics of dynamic class generation such as how to effectively dynamically generate classes.
- How to overcome some of the challenges of dynamic class generation.
- The tradeoffs in dynamically generating classes and discussion on when it is appropriate.
By the end of this talk, the hope is that you will have a better understanding of dynamic class generation and come away with helpful ideas for your next big project.