Installation
Installcodegen on pypi via uv:
This makes the
codegen command available globally in your terminal, while
keeping its dependencies isolated.Quick Start with Jupyter
The codgen notebook command creates a virtual environment and opens a Jupyter notebook for quick prototyping. This is often the fastest way to get up and running.- Create a
.codegen/directory with:.venv/- A dedicated virtual environment for this projectjupyter/- Jupyter notebooks for exploring your codeconfig.toml- Project configuration
- Launch Jupyter Lab with a pre-configured notebook
Initializing a Codebase
Instantiating a Codebase will automatically parse a codebase and make it available for manipulation.This will automatically infer the programming language of the codebase and
parse all files in the codebase.
Exploring Your Codebase
Let’s explore the codebase we just initialized. Here are some common patterns for code navigation in Codegen:- Iterate over all Functions with Codebase.functions
- View class inheritance with Class.superclasses
- View function call-sites with Function.call_sites
- View function usages with Function.usages
Analyzing Tests
Let’s specifically drill into large test files, which can be cumbersome to manage.Splitting Up Large Test Files
Lets split up the largest test files into separate modules for better organization:Finding Specific Content
Once you have a general sense of your codebase, you can filter down to exactly what you’re looking for. Codegen’s graph structure makes it straightforward and performant to find and traverse specific code elements:Safe Code Transformations
Codegen guarantees that code transformations maintain correctness. It automatically handles updating imports, references, and dependencies. Here are some common transformations:Leveraging Graph Relations
Codegen’s graph structure makes it easy to analyze relationships between code elements across files:Learn more about dependencies and
references or imports and exports.
What’s Next?
View Tutorials
Follow step-by-step tutorials for common code transformation tasks like
modernizing React codebases or migrating APIs.
Learn Core Concepts
Understand key concepts like working with files, functions, imports, and the
call graph to effectively manipulate code.
Integrate with AI Tools
Learn how to use Codegen with Cursor, Devin, Windsurf, and more.
API Reference
Explore the complete API documentation for all Codegen classes and methods.