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 + '!'

Indices and tables