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

Installation

Install codegen on Pypi via uv:

Quick Start with Jupyter

The codegen 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.
The notebook --demo comes pre-configured to load FastAPI’s codebase, so you can start exploring right away!
Prefer working in your IDE? See IDE Usage

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. Learn more about parsing codebases 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. This uses Codegen’s codebase.move_to_file(…), which will:
  • update all imports
  • (optionally) move dependencies
  • do so very fast ⚡️
While maintaining correctness.
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:

Advanced Settings

Codegen also supports a number of advanced settings that can be used to customize the behavior of the graph construction process. These flags are helpful for debugging problematic repos, optimizing Codegen’s performance, or testing unreleased or experimental (potentially backwards-breaking) features.
To learn more about available settings, see the Advanced Settings page.
These are considered experimental and unstable features that may be removed or changed in the future.

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.

IDE Setup

Iterate locally with your favorite IDE, work with a debugger and build sophisticated codemods

Integrate with AI Tools

Learn how to use Codegen with Cursor, Devin, Windsurf, and more.