Metaprogramming In The Wild

By Josue Balandrano Coronel

Elevator Pitch

Metaprogramming is the ability of code to write code! We can learn to use metaprogramming by looking at other projects. Projects like Django use metaclasses to build its powerful API. Let’s dive into different projects to see how metaprogramming is used in the wild!



Metaprogramming is the ability of a computer language to write code. This means that code can write code! Developers have used metaprogramming to allow a computer program to generate, analyze and transform code. This is possible even when the code is running.

This technique is very powerful but it can also complicate your code base if not use with care. We can learn how to correctly use metaprogramming by looking at how other stable projects are leveraging these features.

Projects like Django and Django Rest Framework use metaclasses to build its powerful API, helping us programmers to write less code. Let’s dive into different projects and see how metaprogramming is used in the wild!


Metaprogramming is a topic which is too often seen as complicated or “magical”. This talk aims at removing this perceived complexity from metaprogramming. The concept of code creating or modifying code is difficult to grasp. Mainly because the output of a function that generates or modifies code can change depending on the input parameters given, once this idea becomes common to us we can easier leverage metaprogramming in the same way that other bigger projects have. This is the reason why this talk will use examples from known projects and explain how they used metaprogramming to build a great product. I will also present different alternatives to metaprogramming in order to show an alternative solution. This way we can remove the idea of metaprogramming being “magic”. Attendees will understand how creating or modifying code on the fly is not the only solutions to some problems presented here. We can then make a better solution if metaprogramming is a good choice or not. This decision will be made based on features and functionality rather than on misconceptions. Finally, this talk will present tips on how to better transpire how metaprogramming is being used within a project by the use of documentation and testing. This is imperative to avoid the feeling of doing “magical” things and instead pass the correct knowledge to other team members.

Outline ~~~~~~~

  1. Intro a. What is metaprogramming? b. Using decorators c. Using Metaclasses
  2. Into the Wild a. Django’s ORM b. Django Rest Framework c. Elasticsearch-DSL d. Swagger e. Flask
  3. Tips and Tricks a. Writing decorators i. Documenting decorators b. Writing Metaclasses i. Documenting classes c. Writing tests to explain functionality


I have been a Django developer for over 4 years. Currently I work at the Texas Advanced Computing Center building Science Gateways. I am currently starting a project rmcomplexity aimed at removing the perceived complexity from different software development topics. This talk will be further explained in an article at I have written extensive APIs, mainly for internal use, which have leverage metaprogramming in its design.

Attendees do not need any specific knowledge and every concept will be clearly explained in the talk. Attendees will gain a better understanding at how metaprogramming works and how it is being used in the real world. This will give attendees the necessary tools to use metaprogramming correctly and with confidence.