Skip to main content
A quick tour of Codegen in a Jupyter notebook.

Installation

Install codegen 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.
Prefer working in your IDE? See IDE Usage
This will:
  1. Create a .codegen/ directory with:
    • .venv/ - A dedicated virtual environment for this project
    • jupyter/ - Jupyter notebooks for exploring your code
    • config.toml - Project configuration
  2. Launch Jupyter Lab with a pre-configured notebook
The notebook comes pre-configured to load your codebase, so you can start exploring right away!

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.
The initial parse may take a few minutes for large codebases. This pre-computation enables constant-time operations afterward. Learn more here.

Exploring Your Codebase

Let’s explore the codebase we just initialized. Here are some common patterns for code navigation in Codegen:

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:
In order to commit changes to your filesystem, you must call codebase.commit(). Learn more about commit() and reset().

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:
When moving symbols, Codegen will automatically update all imports and references. See Moving Symbols to learn more.

Leveraging Graph Relations

Codegen’s graph structure makes it easy to analyze relationships between code elements across files:

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.