fluent-codegen
fluent-codegen is a Python library for generating Python code via AST
construction. Instead of manipulating raw ast nodes or concatenating strings,
you work with high-level objects like Module,
Function, and
Expression that produce correct Python source
or compilable AST.
from fluent_codegen import codegen
module = codegen.Module()
func, func_name = module.create_function("greet", args=["name"])
name_arg = func.name("name")
func.body.create_return("Hello, " + name_arg.e + "!")
print(module.as_python_source())
# def greet(name):
# return 'Hello, ' + name + '!'
Contents
- Installation
- Usage Guide
- Why fluent-codegen?
- Core Concepts
- Common tasks
- A simple function
- Creating names and using them
- Assignments and variables
- Dataclasses
- Control flow — if / elif / else
- With statements
- For loops
- Comprehensions and generator expressions
- Function arguments — positional, keyword, defaults
- Imports
- String joining / f-strings
- Comments
- Compiling and executing generated code
- E-objects
- Advanced Topics
- Static typing
- Examples
- API Reference
- Changelog