Scriptable interface to a powerful, multi-lingual language server.
Codegen is a python library for manipulating codebases.
from codegen import Codebase
codebase = Codebase("./")
for function in codebase.functions:
if not function.usages:
function.move_to_file('deprecated.py')
Write code that transforms code. Codegen combines the parsing power of Tree-sitter with the graph algorithms of rustworkx to enable scriptable, multi-language code manipulation at scale.
Installation and Usage
We support
- Running Codegen in Python 3.12 – 3.13
- macOS and Linux
- We develop on macOS but our testing and production environments are Linux
- Windows is not supported
- Python, Typescript, Javascript and React codebases
# Install inside existing project
uv pip install codegen
# Install global CLI
uv tool install codegen
# Create a codemod for a given repo
cd path/to/repo
codegen init
codegen create test-function
# Run the codemod
codegen run test-function
# Create an isolated venv with codegen => open jupyter
codegen notebook
Usage
See Getting Started for a full tutorial.
from codegen import Codebase
Resources
Why Codegen?
Software development is fundamentally programmatic. Refactoring a codebase, enforcing patterns, or analyzing control flow - these are all operations that can (and should) be expressed as programs themselves.
We built Codegen backwards from real-world refactors performed on enterprise codebases. Instead of starting with theoretical abstractions, we focused on creating APIs that match how developers actually think about code changes:
-
Natural mental model: Write transforms that read like your thought process - "move this function", "rename this variable", "add this parameter". No more wrestling with ASTs or manual import management.
-
Battle-tested on complex codebases: Handle Python, TypeScript, and React codebases with millions of lines of code.
-
Built for advanced intelligences: As AI developers become more sophisticated, they need expressive yet precise tools to manipulate code. Codegen provides a programmatic interface that both humans and AI can use to express complex transformations through code itself.
Contributing
Please see our Contributing Guide for instructions on how to set up the development environment and submit contributions.
Enterprise
For more information on enterprise engagements, please contact us or request a demo.