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

# Graph-sitter 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. Graph-sitter 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 Graph-sitter 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 graph-sitter

# Install global CLI
uv tool install graph-sitter --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 Graph-sitter 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. Graph-sitter 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.5-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.5-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.5-cp313-cp313-macosx_11_0_arm64.whl (1.0 MB view details)

Uploaded CPython 3.13macOS 11.0+ ARM64

graph_sitter-0.56.5-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.5-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.5-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.5-cp312-cp312-macosx_11_0_arm64.whl (1.0 MB view details)

Uploaded CPython 3.12macOS 11.0+ ARM64

graph_sitter-0.56.5-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.5-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_34_aarch64.whl.

File metadata

File hashes

Hashes for graph_sitter-0.56.5-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 8a0effe1ba2d89c22a4778e3759bcf0b607add11c03ba3274f95a35dcadd12ff
MD5 dfdf9c11dac90e0ab211878b2284397c
BLAKE2b-256 0fa4d7342309557ffec80f03e323f360e1549a2005638808061f2255614c67f8

See more details on using hashes here.

File details

Details for the file graph_sitter-0.56.5-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.5-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 a470c469eb72a010f7edf9475f0047886cc50391805602412361f6d882eba83b
MD5 1a7db2f552475e78acdb92c5fff49e3b
BLAKE2b-256 debf65437690377945ed6eb6fac6fb99e2e02f0c5da3da751c07b022ebd26dde

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for graph_sitter-0.56.5-cp313-cp313-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 4fda8bcdf3f3306abf16e8bbfe9fcc86a55348be97bbdc53ee97d0b9456d2ebd
MD5 4a34cccc2fe513ac1cd5e6594a180876
BLAKE2b-256 5f97b68c1d33dd01a70bf2a5947f90be3ddacbd5ec98808363108f54a9624bd1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for graph_sitter-0.56.5-cp313-cp313-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 793ae1e767d61e85645bf86c43b1b6e264119e2b36b61050db9f6b9c3470481e
MD5 e889d6109cc0f90a629a6a26fc09f103
BLAKE2b-256 9c23629f8c782a436ce897f9df1015c65a6856ef392b8068185956e9ed2e63d4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for graph_sitter-0.56.5-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_34_aarch64.whl
Algorithm Hash digest
SHA256 c8f7e3ccbe661a468674434bc1027cac9843c07fd0d7f7560b22b68e5c80b93b
MD5 ec3c9621f102059c0336eb6f0af13a34
BLAKE2b-256 663a8340ef151da4bcb1b42d158ff859e260404301f6cbd484e24ddc4d44744a

See more details on using hashes here.

File details

Details for the file graph_sitter-0.56.5-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.5-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 3bd8578fbf99512ce4ae8bc548ef74e7f7ca3e6cc8fb9a9801f1c03b6044850a
MD5 9979d3a3a1429194e8e740a317678945
BLAKE2b-256 de6fe0e3d6d765ef3f86c725693fffbf007b246c07b50397171ace97c5d06977

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for graph_sitter-0.56.5-cp312-cp312-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 59e12639f1b9d450109ceca7fca47b6e181c5d2c6efa50df13bd411826126f6c
MD5 80a1a117be6ca62731fe82319f67d4c3
BLAKE2b-256 4972e244eb538a16f86c96074198b4a194c3bc31bd087b1af0012256fe61406b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for graph_sitter-0.56.5-cp312-cp312-macosx_10_13_x86_64.whl
Algorithm Hash digest
SHA256 231233c2ec8844743a01075bd1552dfb7ea2f26fb395a754a4570f6819fccc9a
MD5 59d672d0165cb0234beff2feb429a2ee
BLAKE2b-256 903d6da6593e63c08d5a1e8309ecb47d1fca5daabb5e845aefcade9c4df3122c

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