Skip to main content

Scriptable interface to a powerful, multi-lingual language server built on top of Tree-sitter

Project description


Scriptable interface to a powerful, multi-lingual language server.

PyPI Documentation Slack Community License Follow on X


Codegen is a python library for manipulating codebases.

from codegen import Codebase

# Codegen builds a complete graph connecting
# functions, classes, imports and their relationships
codebase = Codebase("./")

# Work with code without dealing with syntax trees or parsing
for function in codebase.functions:
    # Comprehensive static analysis for references, dependencies, etc.
    if not function.usages:
        # Auto-handles references and imports to maintain correctness
        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 (recommended: Python 3.13+)
  • macOS and Linux
    • macOS is supported
    • Linux is supported on x86_64 and aarch64 with glibc 2.34+
    • Windows is supported via WSL. See here for more details.
  • Python, Typescript, Javascript and React codebases
# Install inside existing project
uv pip install codegen

# Install global CLI
uv tool install codegen --python 3.13

# Create a codemod for a given repo
cd path/to/repo
gs init
gs create test-function

# Run the codemod
gs run test-function

# Create an isolated venv with codegen => open jupyter
gs notebook

Usage

See Getting Started for a full tutorial.

from codegen import Codebase

Troubleshooting

Having issues? Here are some common problems and their solutions:

  • I'm hitting an UV error related to [[ packages ]]: This means you're likely using an outdated version of UV. Try updating to the latest version with: uv self update.
  • I'm hitting an error about No module named 'codegen.sdk.extensions.utils': The compiled cython extensions are out of sync. Update them with uv sync --reinstall-package codegen.
  • I'm hitting a RecursionError: maximum recursion depth exceeded error while parsing my codebase: If you are using python 3.12, try upgrading to 3.13. If you are already on 3.13, try upping the recursion limit with sys.setrecursionlimit(10000).

If you run into additional issues not listed here, please join our slack community and we'll help you out!

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

graph_sitter-0.56.4-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_34_aarch64.whl (2.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64manylinux: glibc 2.34+ ARM64

graph_sitter-0.56.4-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_34_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.13manylinux: glibc 2.34+ x86-64manylinux: glibc 2.5+ x86-64

graph_sitter-0.56.4-cp313-cp313-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

graph_sitter-0.56.4-cp313-cp313-macosx_10_13_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.13macOS 10.13+ x86-64

graph_sitter-0.56.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_34_aarch64.whl (2.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64manylinux: glibc 2.34+ ARM64

graph_sitter-0.56.4-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_34_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.34+ x86-64manylinux: glibc 2.5+ x86-64

graph_sitter-0.56.4-cp312-cp312-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

graph_sitter-0.56.4-cp312-cp312-macosx_10_13_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.12macOS 10.13+ x86-64

File details

Details for the file graph_sitter-0.56.4-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for graph_sitter-0.56.4-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 dcf924dc619eb1904d5d0799eac4229d792fde1c844f8043a814222b4a48111a
MD5 e0da668c76d41564b7b6528729d77fc6
BLAKE2b-256 9341ad55314097cb6fed671a9c6450b33bcbed319bdf1d2d0165416a36c09d32

See more details on using hashes here.

File details

Details for the file graph_sitter-0.56.4-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for graph_sitter-0.56.4-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 72680dca0ad1b88d5f3794d5e11a7ec3d9e08b884d03cb4616bd091393d1dbb0
MD5 2e199989718e984219a24b972f777585
BLAKE2b-256 a987ea04c2d5622a6e4c1e109b2e75c150127b8f51c33567660486352e6fd040

See more details on using hashes here.

File details

Details for the file graph_sitter-0.56.4-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for graph_sitter-0.56.4-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 27baf94a3810b5b9661b984937cf0113bbd4fcc82b57a888152880025b73e644
MD5 837ad5bae4a8622f01598225f3702b82
BLAKE2b-256 36d47517bd9327416e01d1043ad9a8acd800b0378150e090a35aeb0381f56f7a

See more details on using hashes here.

File details

Details for the file graph_sitter-0.56.4-cp313-cp313-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for graph_sitter-0.56.4-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 e8624822925473c0fe73148187870d038f1eda94d77e899e800f47b6254511d6
MD5 d7695453ef5c29a7fe8850a9595181cc
BLAKE2b-256 691a4b74554f821948c4acf135e45e51180ebec3835ec1e0be384e0d490c73ab

See more details on using hashes here.

File details

Details for the file graph_sitter-0.56.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for graph_sitter-0.56.4-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 3bc091a0d996bda4e15c196cb539f9540c3fae23ff042d5cc6bf1c991a24a6fd
MD5 5f7472fa014a65dfdeb6ec8ca6ae069e
BLAKE2b-256 97565770961f06f724ea517e97280a26c1851758cbb4abd1dabaf7ad0426d8d9

See more details on using hashes here.

File details

Details for the file graph_sitter-0.56.4-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for graph_sitter-0.56.4-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 d0cb27f85c493c2a5bb4e4befe82408f7e31bec796ab0b9a4aaabf71a8b47969
MD5 f23ae139b8c9e2bb7c0c811e832a41bb
BLAKE2b-256 1ba115e1c2ef17beae29f3bedda8c83d40c8542c957be476ce1bce356fd5791a

See more details on using hashes here.

File details

Details for the file graph_sitter-0.56.4-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for graph_sitter-0.56.4-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 9f3591bee380611a9335a3db54d3614efb5e1c6aa31b91a17545a32dbf27c71c
MD5 a5de9642f2405c9f19022843099bf9ab
BLAKE2b-256 85105ff16b26ae08ae07f70535aba8264605ff497eedfc13fcda6910334a051d

See more details on using hashes here.

File details

Details for the file graph_sitter-0.56.4-cp312-cp312-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for graph_sitter-0.56.4-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 2590f49ea2cdbecb4f8309e81c4244c679f81ea99fa054161e103f52387b677d
MD5 6577aa0292162d97b85eb9b5a6f87e44
BLAKE2b-256 b3e2e0caa6171bfb97912e56e43147dfe131a8da0518e1f22d6154156f333936

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page