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
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

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


Release history Release notifications | RSS feed

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

codegen-0.52.25-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_34_aarch64.whl (2.1 MB view details)

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

codegen-0.52.25-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_34_x86_64.whl (2.2 MB view details)

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

codegen-0.52.25-cp313-cp313-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.13 macOS 11.0+ ARM64

codegen-0.52.25-cp313-cp313-macosx_10_13_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.13 macOS 10.13+ x86-64

codegen-0.52.25-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_34_aarch64.whl (2.1 MB view details)

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

codegen-0.52.25-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_34_x86_64.whl (2.2 MB view details)

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

codegen-0.52.25-cp312-cp312-macosx_11_0_arm64.whl (1.1 MB view details)

Uploaded CPython 3.12 macOS 11.0+ ARM64

codegen-0.52.25-cp312-cp312-macosx_10_13_x86_64.whl (1.1 MB view details)

Uploaded CPython 3.12 macOS 10.13+ x86-64

File details

Details for the file codegen-0.52.25-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for codegen-0.52.25-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 bd92d5b690c7d554a3d4f3881f70c3c1f1028a6c597af3773f3aeb67b44f61f3
MD5 026e4b1053c0d864182b6dc9e3e33b3f
BLAKE2b-256 ff9484a756fe148a2a95dd966a7eb932ed35e9430940c124a40e7f73cf83cd4c

See more details on using hashes here.

File details

Details for the file codegen-0.52.25-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for codegen-0.52.25-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 3528d8a4b3ee1ae866cbef83e848caa47f91bbeae17d127cb2744d7e65820921
MD5 c2f9466d5dc0050c10567b918ffac4e6
BLAKE2b-256 79c4b611580ac12df776f771850ecd28d35e45f8ee1ecf738da29639deb87e69

See more details on using hashes here.

File details

Details for the file codegen-0.52.25-cp313-cp313-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for codegen-0.52.25-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 f3b1d82ba8950cc2d840da4dcf73e5f88b476a39517da2fee203979188d853a7
MD5 969f2d7aba8f0f32708fb5f04b7be01b
BLAKE2b-256 822016b904af63c33af570cdf747770ad492306c0f12b77f58a4763e686e02f8

See more details on using hashes here.

File details

Details for the file codegen-0.52.25-cp313-cp313-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for codegen-0.52.25-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 9c259fd1f9828deab5ac5b9dd9fb657ded539f377d43bf9a2e332a993ce66ab9
MD5 29a20803a0345ef63bd5df52321d9ba2
BLAKE2b-256 f2fbac42bf9515516dd2039c3e266bb84eff3e88065fd699ea7264cafc73c1ca

See more details on using hashes here.

File details

Details for the file codegen-0.52.25-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for codegen-0.52.25-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 16be0668c28ed72a4b37b361229637a61145cfd416149062e94e5dcb61e497f4
MD5 1465a1108f6aba072a5e063f3da8b325
BLAKE2b-256 85c2edcf2153aab4c2f252411d337327487d03cc67c5e74fdf04173ae73d36cc

See more details on using hashes here.

File details

Details for the file codegen-0.52.25-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for codegen-0.52.25-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 0bf907f7d2c5dbd93d69345b4c1bcd6ddb06bca4167a2477c0630db4acdcd485
MD5 9865e767743d67eefb321500e0e925ae
BLAKE2b-256 14205183ff25d895efa90f115dce24e32de2a2a52171a77826795c95aef6c5f3

See more details on using hashes here.

File details

Details for the file codegen-0.52.25-cp312-cp312-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for codegen-0.52.25-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 97b6022613131fb0e073ee04f72a7b01eb0f84dab6c9566515cb6cd6e71bca6f
MD5 1a03e2c1afa51bab6ded1412f1f44989
BLAKE2b-256 79fba3d277be50287b52b18cf40e49505c1e3557f300ecfb7d5201d3eeb8312b

See more details on using hashes here.

File details

Details for the file codegen-0.52.25-cp312-cp312-macosx_10_13_x86_64.whl.

File metadata

File hashes

Hashes for codegen-0.52.25-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 5d3957483d83e86eb106bb9d9adcde4a0ff69f4626d91a57339c5dc95012306d
MD5 578b427f4fab7b5daa0e328c45072d10
BLAKE2b-256 ad7e6707151e971bf6104ad6ebe1d69b71db27eb9f1fe2a80f6c9ebc1d2ce12d

See more details on using hashes here.

Supported by

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