Best suggestion: try them all. It won't take long.

My favourite: Jinja2 (by a mile)

It has decent syntax, can trace errors through it, and is sandboxable.

Answer from Ali Afshar on Stack Overflow
🌐
GitHub
github.com › modm-io › lbuild
GitHub - modm-io/lbuild: lbuild: a generic, modular code generator in Python 3 · GitHub
The Library Builder (pronounced lbuild) is a BSD licensed Python 3 tool for describing repositories containing modules which can copy or generate a set of files based on the user provided data and options. lbuild allows splitting up complex ...
Starred by 43 users
Forked by 11 users
Languages   Python
🌐
GitHub
github.com › umutboz › code-gen-lib
GitHub - umutboz/code-gen-lib: Python Code Generation Library
Python Code Generation Library. Contribute to umutboz/code-gen-lib development by creating an account on GitHub.
Starred by 4 users
Forked by 2 users
Languages   Python 51.3% | Swift 44.5% | PowerShell 3.0% | Python 51.3% | Swift 44.5% | PowerShell 3.0%
Discussions

templates - Best Python templating library to facilitate code generation - Stack Overflow
Instead of me spending the next day (or year) reading about them all, are there any suggestions for templating engines that I should look into in more detail? More on stackoverflow.com
🌐 stackoverflow.com
Python Code Generation Tools
I'd probably use metaclasses if I had the kind of problem where code generation could actually help. The last time I saw a project using code generation where I thought that it ought have to used metaclasses was a tool to generate python code from swagger descriptions. Django's ORM is a good example where metaclasses were used to good effect (there are very few of those). In general I'm extremely suspicious of anybody who claims to have the kind of problem that requires either metaclasses or code generation would help though. It is suitable only for problems that are very, very, very abstract (e.g. like an ORM or REST API interaction framework). In 90% of cases I've seen the person attempting to use it vastly overgeneralized the problem that they actually had in an attempt to prepare for future problems never arose. In the process of doing that they then created a code clusterfuck that was hellishly hard to understand and debug (and in some cases I was left to clean up the mess). It wasn't simple and it can't, intrinsically, ever be simple (there is some language theory behind this). I could be convinced otherwise by describing your problem, but right now I'm 80% convinced that what you have described is an XY problem and that you're attempting to do this because you overgeneralized your problem. If you describe the actual problem you're solving it might help. More on reddit.com
🌐 r/Python
18
8
March 9, 2019
Is there a code generator library for Rust?
Sounds like you are looking for something like aster . It's not beta/stable friendly, though. More on reddit.com
🌐 r/rust
17
7
May 15, 2015
Using Python to create music?
https://en.wikipedia.org/wiki/Python_(programming_language) https://en.wikipedia.org/wiki/Audio_engineering https://en.wikipedia.org/wiki/Musical_acoustics Topic :: Multimedia :: Sound/Audio https://wiki.python.org/moin/PythonInMusic Books: http://www.worldcat.org/title/introduction-to-computing-programming-in-python-a-multimedia-approach/oclc/794621146 http://www.crcpress.com/product/isbn/9781439867914 http://musicforgeeksandnerds.com/ ( http://kroger.github.io/pyknon/ looks really easy) http://www.class-central.com/search?q=music https://www.coursera.org/course/chuck101 http://chuck.cs.princeton.edu/ https://pypi.python.org/pypi/audiolazy/0.05 https://en.wikipedia.org/wiki/Keytar More on reddit.com
🌐 r/Python
23
48
September 22, 2013
🌐
GitHub
github.com › yuchdev › code_generator
GitHub - yuchdev/code_generator: Simple and straightforward code generator for creating program code. At the moment offers support for C++, Java and HTML5 for generating reports.
Simple and straightforward code generator for creating C++ code. It also could be used for generating code in any programming language. Written in Python, works both with Python 2 and 3
Starred by 100 users
Forked by 21 users
Languages   Python 97.9% | C++ 1.9% | C 0.2% | Python 97.9% | C++ 1.9% | C 0.2%
🌐
GitHub
github.com › pyecore › pyecoregen
GitHub - pyecore/pyecoregen: Python Model to Text framework for PyEcore, including the Ecore to Python generator
The generated classes are instances of the pyecore metaclasses. Please see pyecore for documentation how to work with them. pyecoregen comes in form or a regular Python distribution and can be installed from Github or PyPI with a simple: ... The library works with any version of Python >= 3.5. Code generation can be done programmatically and directly at the command line.
Starred by 32 users
Forked by 6 users
Languages   Python 82.2% | Smarty 17.8% | Python 82.2% | Smarty 17.8%
🌐
GitHub
github.com › topics › code-generator
code-generator · GitHub Topics · GitHub
Code generation tool, creates python / C programs that parse command line arguments.
🌐
GitHub
github.com › cogu › cfile
GitHub - cogu/cfile: A python C code generator · GitHub
A python C code generator. Contribute to cogu/cfile development by creating an account on GitHub.
Starred by 92 users
Forked by 25 users
Languages   Python 99.7% | Batchfile 0.3%
Find elsewhere
🌐
Reddit
reddit.com › r/python › python code generation tools
r/Python on Reddit: Python Code Generation Tools
March 9, 2019 -

What do you guys use to generate Python code? I saw that a lot of people just use Jinja2 with some templates, which looks simple and powerful. You still have to generate the environments and write the templates. Now I'm looking around whether someone already did the work of generalizing that step (thinking about fields in classes, inheritance, constructors etc. and how to map that data to the environment) or whether I have to do it myself.

TLDR: Are there simple but powerful Python code generation "frameworks"?

EDIT:

  • I found pymultigen. Seems like it helps with creating code in multiple files.

  • Looks like pyecoregen is a specialized multi-file code generator based on pymultigen.

Top answer
1 of 3
2
I'd probably use metaclasses if I had the kind of problem where code generation could actually help. The last time I saw a project using code generation where I thought that it ought have to used metaclasses was a tool to generate python code from swagger descriptions. Django's ORM is a good example where metaclasses were used to good effect (there are very few of those). In general I'm extremely suspicious of anybody who claims to have the kind of problem that requires either metaclasses or code generation would help though. It is suitable only for problems that are very, very, very abstract (e.g. like an ORM or REST API interaction framework). In 90% of cases I've seen the person attempting to use it vastly overgeneralized the problem that they actually had in an attempt to prepare for future problems never arose. In the process of doing that they then created a code clusterfuck that was hellishly hard to understand and debug (and in some cases I was left to clean up the mess). It wasn't simple and it can't, intrinsically, ever be simple (there is some language theory behind this). I could be convinced otherwise by describing your problem, but right now I'm 80% convinced that what you have described is an XY problem and that you're attempting to do this because you overgeneralized your problem. If you describe the actual problem you're solving it might help.
2 of 3
2
If you're looking for some codegen support stuffs in python, I'd give you some info Python std module ast AST to python source code emitter, unparse. https://github.com/python/cpython/blob/master/Tools/parser/unparse.py AST based scoping analyzer, https://github.com/thautwarm/scoping-resolver
🌐
GitHub
github.com › inducer › genpy
GitHub - inducer/genpy: An AST for Python code generation, in Python · GitHub
An AST for Python code generation, in Python. Contribute to inducer/genpy development by creating an account on GitHub.
Starred by 32 users
Forked by 6 users
Languages   Python
🌐
GitHub
github.com › Siddarthsangavi › Python-Code-Generator
GitHub - Siddarthsangavi/Python-Code-Generator
Clone the repository https://github.com/Siddarthsangavi/Python-Code-Generator ... The biggest learning we had while developing this prototype was the practical implementation of fine-tuning a transformer-based model for a specific NLP task.
Author   Siddarthsangavi
🌐
GitHub
github.com › AvishakeAdhikary › Python-Code-Generator
GitHub - AvishakeAdhikary/Python-Code-Generator: A pre-trained language model to generate code based on user input. It prompts the user to enter a prompt, tokenizes the input, and generates a sequence of tokens based on the input using a pre-trained model. The generated sequence is then decoded and printed to the console. · GitHub
This is a Python code for generating code snippets using the pre-trained language model from Salesforce called CodeGPT. This code uses the Hugging Face Transformers library, which provides an easy-to-use interface to access the pre-trained models.
Author   AvishakeAdhikary
🌐
GitHub
github.com › visualpython › visualpython
GitHub - visualpython/visualpython: GUI-based Python code generator for data science, extension to Jupyter Lab, Jupyter Notebook and Google Colab. · GitHub
GUI-based Python code generator for data science, extension to Jupyter Lab, Jupyter Notebook and Google Colab. - visualpython/visualpython
Starred by 918 users
Forked by 118 users
Languages   JavaScript 87.3% | HTML 5.5% | CSS 5.3% | Python 1.0% | Jupyter Notebook 0.3% | Batchfile 0.3% | Shell 0.3%
🌐
Qodo
qodo.ai › blog › news & updates › top 7 python code generator tools in 2025
Top 7 Python Code Generator Tools in 2025 - Qodo
May 16, 2025 - One of the most important features of GitHub Copilot is its context awareness. This helps produce more relevant output that is in line with the coding style and standards followed in the given project.
🌐
GitHub
github.com › 2020saurav › py-codegen
GitHub - 2020saurav/py-codegen · GitHub
library.py [Python source code to be compiled using our compiler and to be used as library for the language] ... runTimeCode.py [ Python source which is used for efficient allocation & maintenance of registers as a helper function for codegen.py ...
Starred by 4 users
Forked by 2 users
Languages   Python 94.3% | Assembly 5.6% | Makefile 0.1%
🌐
GitHub
github.com › microsoft › PyCodeGPT
GitHub - microsoft/PyCodeGPT: A pre-trained GPT model for Python code completion and generation
A pre-trained GPT model for Python code completion and generation - microsoft/PyCodeGPT
Starred by 282 users
Forked by 41 users
Languages   Python 96.8% | Shell 2.8% | Jupyter Notebook 0.4% | Python 96.8% | Shell 2.8% | Jupyter Notebook 0.4%
🌐
GitHub
github.com › mirumee › ariadne-codegen
GitHub - mirumee/ariadne-codegen: Generate fully typed Python client for any GraphQL API from schema, queries and mutations · GitHub
Python code generator that takes graphql schema, queries, mutations and subscriptions and generates Python package with fully typed and asynchronous GraphQL client.
Starred by 393 users
Forked by 67 users
Languages   Python
🌐
GitHub
github.com › biojppm › regen
GitHub - biojppm/regen: Easy C++ reflection and code generation
regen is a python3 package providing C/C++ reflection and source-code generation. You provide your own code generation templates , and have full control over where the generated code goes.
Starred by 39 users
Forked by 7 users
Languages   Python 71.2% | C++ 19.4% | CMake 8.9% | Shell 0.5% | Python 71.2% | C++ 19.4% | CMake 8.9% | Shell 0.5%
🌐
GitHub
github.com › topics › code-generation
code-generation · GitHub Topics · GitHub
nlp paper coding dataset code-generation synthetic-data synthetic-dataset-generation large-language-models supervised-finetuning ... Generate Python API client libraries from Protocol Buffers.
🌐
GitHub
github.com › topics › codegenerator
codegenerator · GitHub Topics
DWH SQL CodeGen is a cross-platform GUI application that generates SQL scripts to build and load DWH (PostgreSQL/Redshift) from staging tables · python postgres sql etl sqlite postgresql wxwidgets codegenerator sqlite3 sql-builder redshift ...
🌐
Python
python.org › about › success › cog
Cog: A Code Generation Tool Written in Python
For each chunk of generator code it finds, Cog will: ... In a word, great. We now have a powerful tool that lets us maintain a single XML file that describes our data schema. Developers changing the schema have a simple tool to run that generates code from the schema, producing output code in four different languages across 50 files.