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 › pyscaffold › pyscaffold
GitHub - pyscaffold/pyscaffold: 🛠 Python project template generator with batteries included
🛠 Python project template generator with batteries included - pyscaffold/pyscaffold
Starred by 2.3K users
Forked by 185 users
Languages   Python
Discussions

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
Generate python code from a generic template
This sounds like an X-Y question, I think you should describe your larger goal rather than asking how to implement this specific solution. Generating code is usually a bad idea and usually not necessary. More on reddit.com
🌐 r/learnpython
7
0
February 7, 2023
[Python] Simple but powerful project template
Hey folks! Sharing my Python project template. I've been using (and improving) it since 2016, but this is the first year it's an actual GitHub template. It handles: creating stub files each day reading your test & live inputs parsing a few pre-defined input types (string-per-line, int, etc) running your solution, profiling, debugging, and a few more niceties. storing any helper functions you write It doesn't do any automatic downloading or submitting, but makes it easy to do those yourself; I personally like a more simplistic approach. It also includes a minimal linting/formatting setup! I'll also be sharing step-by-step solutions (using the above) each day if anyone gets stuck. My goal is that anyone with programming experience can understand the solution to literally every AoC puzzle, so they really break each problem down. I've got solutions for every puzzle going back to 2020. Check it all out here: https://advent-of-code.xavd.id/ More on reddit.com
🌐 r/adventofcode
2
3
November 29, 2023
Python project template

I recommend looking into cookiecutter for the next steps on your todo

More on reddit.com
🌐 r/Python
5
12
October 21, 2023
🌐
GitHub
github.com › Rookfighter › code-template
GitHub - Rookfighter/code-template: Create code files from templates. · GitHub
A command line utility to generate code files from templates written in python.
Author   Rookfighter
🌐
GitHub
github.com › Python-templates
Python templates · GitHub
Project templates coded in python. ... Beginner machine learning template for projects based on sklearn library. ... PyTorch deep learning projects made easy. ... Full stack, modern web application generator.
🌐
Koxudaxi
koxudaxi.github.io › datamodel-code-generator › custom_template
Custom template - datamodel-code-generator
Now, you can use the --custom-template-dir option to generate the data model with your custom template: $ datamodel-codegen --input person.json --output person.py --custom-template-dir custom_templates
🌐
GitHub
github.com › modm-io › lbuild
GitHub - modm-io/lbuild: lbuild: a generic, modular code generator in Python 3 · GitHub
lbuild allows splitting up complex code generation projects into smaller modules with configurable options, and provides for their transparent discovery, documentation and dependency management. Each module is written in Python 3 and declares its options and how to generate its content via the Jinja2 templating engine or a file/folder copy.
Starred by 43 users
Forked by 11 users
Languages   Python
🌐
GitHub
github.com › jacebrowning › template-python
GitHub - jacebrowning/template-python: My template for new Python libraries.
My template for new Python libraries. Contribute to jacebrowning/template-python development by creating an account on GitHub.
Starred by 672 users
Forked by 102 users
Languages   Python 85.7% | Makefile 13.6% | Shell 0.7% | Python 85.7% | Makefile 13.6% | Shell 0.7%
🌐
Blue Book
lyz-code.github.io › blue-book › coding › python › python_project_template
Python Project template - The Blue Book
I've automated the creation of the python project skeleton following most of these section guidelines with this cookiecutter template. cruft create https://github.com/lyz-code/cookiecutter-python-project
Find elsewhere
🌐
GitHub
github.com › rochacbruno › python-project-template
GitHub - rochacbruno/python-project-template: This template is **archived**. > UV can now [generate a sample project](https://docs.astral.sh/uv/guides/projects/#creating-a-new-project) > I recommend using **UV** to bootstrap your peojects. > [Copier](https://github.com/copier-org/copier) is a tools that can bootstrap projects from templates. · GitHub
If you want codecov Reports and ... and CODECOV_TOKEN (get the tokens on respective websites) ... Then clone your new project and happy coding! NOTE: WAIT until first CI run on github actions before cloning your new project. 🖼️ Templates for starting multiple application types: Basic low dependency Python program (default) use this template · Flask with database, admin interface, restapi and authentication use this template. or Run make init after cloning to generate a new project ...
Starred by 1.2K users
Forked by 184 users
Languages   Makefile 59.0% | Python 39.9% | Dockerfile 1.1%
🌐
GitHub
gist.github.com › calebrob6 › eb98725187425c527567
General python program template · GitHub
General python program template. GitHub Gist: instantly share code, notes, and snippets.
🌐
GitHub
github.com › topics › python-template
python-template · GitHub Topics · GitHub
python template flask boilerplate generator project-template cookiecutter hacktoberfest python-template python-project-template github-actions rochacbruno-template
🌐
GitHub
github.com › topics › template-generator
template-generator · GitHub Topics · GitHub
python template package template-project python-template template-generator package-template ... Write and use single file templates from the command line. template jinja2 python3 code-generation template-generator
🌐
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 › topics › python-project-template
python-project-template · GitHub Topics · GitHub
python template boilerplate generator cookiecutter gitlab-ci uv python-project-template github-actions ... Yet another Python project template. python template project-template template-project python-project python-project-template template-repository ... A great project template using cookiecutter, uv, taskipy, mkdocs[material], code ...
🌐
GitHub
gist.github.com › nhoffman › 3006600
Python script template · GitHub
Python script template. GitHub Gist: instantly share code, notes, and snippets.
🌐
GitHub
github.com › indrajit912 › TemplateGenerator
GitHub - indrajit912/TemplateGenerator: A python project that can generate project template such as `pyprojec`, `flaskapp` etc.
This repository contains a Python package named template_generator developed by Indrajit Ghosh. This package provides classes for generating project templates and creating project structures with ease.
Author   indrajit912
🌐
GitHub
github.com › scottclowe › python-template-repo
GitHub - scottclowe/python-template-repo: Template repository for Python projects · GitHub
Template repository for Python projects. Contribute to scottclowe/python-template-repo development by creating an account on GitHub.
Starred by 62 users
Forked by 12 users
Languages   Python
🌐
GitHub
github.com › TezRomacH › python-package-template
GitHub - TezRomacH/python-package-template: 🚀 Your next Python package needs a bleeding-edge project structure.
February 7, 2024 - Ready-to-use Pull Requests templates and several Issue templates. Files such as: LICENSE, CONTRIBUTING.md, CODE_OF_CONDUCT.md, and SECURITY.md are generated automatically.
Starred by 1.1K users
Forked by 123 users
Languages   Python 56.1% | Makefile 39.0% | Dockerfile 4.9% | Python 56.1% | Makefile 39.0% | Dockerfile 4.9%
🌐
Python
wiki.python.org › moin › Templating
Templating - Python Wiki
Mirrored on GitHub. webhelpers.htmlgen Kind of like HTMLGen, only much simpler. Like stan, only not. html Provides a simple syntax to generate HTML, XHTML and XML. ... pyhtmloo pyhtmloo is a library that allows python developers to use HTML code like any other python objects. Yattag Provides a readable way to write HTML or XML within Python using indented blocks instead of <tag>...</tag> constructs. Static website generators are more than templating engines in that they create the whole site structure, not just individual files.
🌐
PyPI
pypi.org › project › pymultigen
Client Challenge
JavaScript is disabled in your browser · Please enable JavaScript to proceed · A required part of this site couldn’t load. This may be due to a browser extension, network issues, or browser settings. Please check your connection, disable any ad blockers, or try using a different browser