### Start Development Server Source: https://github.com/codegen-sh/graph-sitter/blob/develop/docs/README.md Run this command from the `docs/` directory to start the development server with hot reloading. Ensure Mintlify is installed globally. ```bash npm i -g mintlify mintlify dev --port 3333 ``` -------------------------------- ### Install and Run Graph-sitter Data Generation Source: https://github.com/codegen-sh/graph-sitter/blob/develop/examples/examples/generate_training_data/README.md Installs the Graph-sitter library and executes the data generation script. This is the primary command to start the pre-training data creation process. ```bash # Install Graph-sitter pip install graph-sitter # Run the data generation python run.py ``` -------------------------------- ### Run Research Tool with Initial Query Source: https://github.com/codegen-sh/graph-sitter/blob/develop/docs/tutorials/deep-code-research.mdx Start the research tool with a specific query to guide the initial analysis of a repository. ```bash python run.py research "fastapi/fastapi" -q "Explain the main components" ``` -------------------------------- ### Install Graph-sitter with uv Source: https://github.com/codegen-sh/graph-sitter/blob/develop/docs/graph-sitter/getting-started.mdx Install the graph-sitter tool using the uv package installer. ```bash uv tool install graph-sitter ``` -------------------------------- ### Install and Run Migration Script (Bash) Source: https://github.com/codegen-sh/graph-sitter/blob/develop/examples/examples/promises_to_async_await/README.md Commands to install the Graph-sitter library and execute the promise to async/await migration script. ```bash pip install graph-sitter python run.py ``` -------------------------------- ### Install Graph-sitter and Dependencies Source: https://github.com/codegen-sh/graph-sitter/blob/develop/examples/examples/modules_dependencies/README.md Installs the necessary libraries, graph-sitter and networkx, using pip. ```bash # install graph-sitter and dependencies pip install graph-sitter networkx ``` -------------------------------- ### Install and Run Graph-sitter Source: https://github.com/codegen-sh/graph-sitter/blob/develop/examples/examples/dict_to_schema/README.md Provides commands to install the Graph-sitter library and execute the conversion script. ```bash # Install Graph-sitter pip install graph-sitter # Run the conversion python run.py ``` -------------------------------- ### Initialize Graph-Sitter with Defaults Source: https://github.com/codegen-sh/graph-sitter/blob/develop/docs/cli/init.mdx Run this command from within a Git repository to initialize Graph-Sitter using the current repository's name and organization. This is the simplest way to get started. ```bash gs init ``` -------------------------------- ### Example Directory Structure with Local Input Repo Source: https://github.com/codegen-sh/graph-sitter/blob/develop/examples/STRUCTURE.md Illustrates the directory structure when using a local `input_repo/` for a Graph-sitter example. This includes the main script and the directory containing the custom code. ```text example-name/ ├── README.md ├── run.py └── input_repo/ # Your minimal example code ├── app.py └── utils.py ``` -------------------------------- ### Install Graph-sitter SDK Source: https://github.com/codegen-sh/graph-sitter/blob/develop/docs/introduction/api.mdx Install the Graph-sitter SDK using pip or uv. This command is used to set up the necessary libraries for interacting with the Codegen API. ```bash pip install graph-sitter # or uv pip install graph-sitter ``` -------------------------------- ### Standard File Structure for Graph-sitter Examples Source: https://github.com/codegen-sh/graph-sitter/blob/develop/examples/STRUCTURE.md This is the recommended file structure for organizing Graph-sitter examples. It includes a README for documentation, a run.py for the main implementation, and an optional input_repo for sample code. ```text example-name/ ├── README.md # Documentation and usage examples ├── run.py # Main implementation └── input_repo/ # (Optional) Sample code for transformation ``` -------------------------------- ### Example Codebase Structure Source: https://github.com/codegen-sh/graph-sitter/blob/develop/architecture/external/dependency-manager.md Illustrates the initial directory structure before Dependency Manager operations. ```bash repo/ ├── package.json ├── node_modules/ ├── src/ │ ├── frontend/ │ │ └── package.json │ └── backend/ │ └── package.json └── tests/ └── package.json ``` -------------------------------- ### Install and Run Migration Script Source: https://github.com/codegen-sh/graph-sitter/blob/develop/examples/examples/freezegun_to_timemachine_migration/README.md Provides the bash commands to install the necessary Graph-sitter library and execute the migration script. ```bash # Install Graph-sitter pip install graph-sitter # Run the migration python run.py ``` -------------------------------- ### Get General Codebase Statistics Source: https://github.com/codegen-sh/graph-sitter/blob/develop/docs/tutorials/codebase-analytics-dashboard.mdx These Python examples demonstrate how to retrieve general codebase statistics using graph-sitter. It shows how to count files, functions, and classes. ```python num_files = len(codebase.files(extensions="*")) num_functions = len(codebase.functions) num_classes = len(codebase.classes) ``` -------------------------------- ### Install Dependencies Source: https://github.com/codegen-sh/graph-sitter/blob/develop/examples/examples/modal_repo_rag/README.md Install the necessary Python packages for Modal, Graph-sitter, and OpenAI. This is a prerequisite for running the application. ```bash pip install modal-client codegen openai ``` -------------------------------- ### Install Graph-sitter CLI Source: https://github.com/codegen-sh/graph-sitter/blob/develop/README.md Install the Graph-sitter command-line interface globally using uv. Ensure you are using Python 3.13+. ```bash # Install inside existing project uv pip install graph-sitter # Install global CLI uv tool install graph-sitter --python 3.13 ``` -------------------------------- ### Install uv Source: https://github.com/codegen-sh/graph-sitter/blob/develop/docs/introduction/installation.mdx Installs the uv package manager, recommended for installing Graph-sitter. Run this command in your terminal. ```bash curl -LsSf https://astral.sh/uv/install.sh | sh ``` -------------------------------- ### Install Dependencies and Run Visualizations Source: https://github.com/codegen-sh/graph-sitter/blob/develop/examples/examples/visualize_codebases/README.md Provides commands to install necessary Python packages and run various visualization scripts. Use these commands to set up your environment and generate codebase graphs. ```bash # Install dependencies pip install graph-sitter networkx # Run any visualization script python call_trace.py # Function call relationships python dependency_trace.py # Symbol dependencies python blast_radius.py # Function blast radius python method_relationships.py # Class method relationships ``` -------------------------------- ### Install Graph-sitter Source: https://github.com/codegen-sh/graph-sitter/blob/develop/examples/examples/cyclomatic_complexity/README.md Installs the Graph-sitter library using pip. This is a prerequisite for running the analysis script. ```bash # Install Graph-sitter pip install graph-sitter ``` -------------------------------- ### Install MCP Library Source: https://github.com/codegen-sh/graph-sitter/blob/develop/docs/tutorials/build-mcp.mdx Install the MCP Python library using uv pip. ```bash uv pip install mcp ``` -------------------------------- ### Install Frontend Dependencies Source: https://github.com/codegen-sh/graph-sitter/blob/develop/examples/examples/ai_impact_analysis/dashboard/README.md Installs Node.js dependencies for the Next.js frontend application. ```bash cd frontend npm install ``` -------------------------------- ### Start Local Modal API Server Source: https://github.com/codegen-sh/graph-sitter/blob/develop/examples/examples/modal_repo_analytics/README.md Run this command to start the Modal API server locally for development and testing. ```bash modal serve src/graph_sitter.extensions/modal/api.py ``` -------------------------------- ### Install Dependencies with Modal Source: https://github.com/codegen-sh/graph-sitter/blob/develop/examples/examples/modal_repo_analytics/README.md Use this command to install the necessary Modal dependency for your project. ```bash uv add modal ``` -------------------------------- ### Start API Server Source: https://github.com/codegen-sh/graph-sitter/blob/develop/examples/examples/modal_repo_rag/README.md Start the local development server for the RAG Q&A API using the 'modal serve' command. This command will run the 'api.py' script and make the API accessible locally. ```bash modal serve api.py ``` -------------------------------- ### Start Frontend Development Server Source: https://github.com/codegen-sh/graph-sitter/blob/develop/examples/examples/ai_impact_analysis/dashboard/README.md Launches the Next.js development server for the frontend application. ```bash npm run dev ``` -------------------------------- ### Install and Run Graph-sitter Migration Script Source: https://github.com/codegen-sh/graph-sitter/blob/develop/examples/examples/flask_to_fastapi_migration/README.md Installs the `graph-sitter` library using pip and executes the migration script `run.py`. The script processes Python files in the `repo-before` directory. ```bash # Install Graph-sitter pip install graph-sitter # Run the migration python run.py ``` -------------------------------- ### Install Backend Dependencies Source: https://github.com/codegen-sh/graph-sitter/blob/develop/examples/examples/ai_impact_analysis/dashboard/README.md Installs necessary Python packages for the backend service, including Modal for deployment, graph-sitter for code analysis, and FastAPI for the API. ```bash uv venv source .venv/bin/activate uv pip install modal graph-sitter fastapi ``` -------------------------------- ### Install and Run Analysis Script Source: https://github.com/codegen-sh/graph-sitter/blob/develop/examples/examples/repo_analytics/README.md Installs the Graph-sitter library using pip and executes the main analysis script. Assumes Python environment is set up. ```bash # Install Graph-sitter pip install graph-sitter # Run the analysis python run.py ``` -------------------------------- ### Example MCP Server Configuration Source: https://github.com/codegen-sh/graph-sitter/blob/develop/examples/examples/codegen-mcp-server/README.md A JSON configuration file example for setting up the codegen-mcp server. This configuration can be used with tools like Cline or Claude desktop. ```json { "mcpServers": { "codegen-mcp": { "command": "uvx", "args": [ "--from", "git+https://github.com/codegen-sh/graph-sitter.git#egg=codegen-mcp-server&subdirectory=examples/examples/codegen-mcp-server", "codegen-mcp-server" ], "disabled": false, "autoApprove": [] } } } ``` -------------------------------- ### Getting All Files vs. Source Files Source: https://github.com/codegen-sh/graph-sitter/blob/develop/src/graph_sitter/system-prompt.txt Illustrates how to retrieve all files, including non-code files, by specifying extensions, versus getting only source files by default. ```python # Get all source files in the codebase source_files = codebase.files ``` ```python # Get all files in the codebase (including non-code files) all_files = codebase.files(extensions="*") ``` -------------------------------- ### FastAPI Route Decorator Example Source: https://github.com/codegen-sh/graph-sitter/blob/develop/src/graph_sitter/system-prompt.txt Shows the equivalent FastAPI-style route decorator after migration. ```python @app.post("/users") def create_user(): pass ``` -------------------------------- ### Set Up Development Environment with UV Source: https://github.com/codegen-sh/graph-sitter/blob/develop/CONTRIBUTING.md Create a virtual environment, activate it, and install development dependencies using UV. ```bash uv venv source .venv/bin/activate uv sync --dev ``` -------------------------------- ### Python 3 input Example Source: https://github.com/codegen-sh/graph-sitter/blob/develop/docs/tutorials/python2-to-python3.mdx Shows the equivalent `input()` call in Python 3. ```python name = input("Enter your name: ") ``` -------------------------------- ### Python 2 raw_input Example Source: https://github.com/codegen-sh/graph-sitter/blob/develop/docs/tutorials/python2-to-python3.mdx Illustrates the usage of `raw_input()` in Python 2 to get user input. ```python name = raw_input("Enter your name: ") ``` -------------------------------- ### Setup Repository Analysis Source: https://github.com/codegen-sh/graph-sitter/blob/develop/examples/examples/ai_impact_analysis/README.md Configure and initialize the repository for analysis. Use the current directory if it's a git repo, search parent directories, or clone a specified repository. ```python import os # Basic repository setup repo_path = os.getcwd() repo_config = RepoConfig.from_repo_path(repo_path) repo_operator = RepoOperator(repo_config=repo_config) project = ProjectConfig.from_repo_operator(repo_operator=repo_operator, programming_language=ProgrammingLanguage.PYTHON) codebase = Codebase(projects=[project]) ``` -------------------------------- ### Python Direct Usage Example Source: https://github.com/codegen-sh/graph-sitter/blob/develop/docs/building-with-graph-sitter/dependencies-and-usages.mdx Demonstrates a direct usage of a symbol within the same file. ```python # Define MyClass class MyClass: def __init__(self): pass # Direct usage of MyClass in same file class Child(MyClass): pass ``` -------------------------------- ### Reference Implementation: Entry Point Source: https://github.com/codegen-sh/graph-sitter/blob/develop/examples/STRUCTURE.md The clean entry point for the `generate_training_data` example. It shows initialization, running the main function, and includes progress messages. ```python # Clean entry point if __name__ == "__main__": print("Initializing codebase...") codebase = Codebase.from_repo("fastapi/fastapi") run(codebase) # ... rest of execution ``` -------------------------------- ### FreezeGun Time Manipulation Example Source: https://github.com/codegen-sh/graph-sitter/blob/develop/examples/examples/freezegun_to_timemachine_migration/README.md Shows how to manually control time mocking using FreezeGun's freezer object, including starting, moving time, and stopping. ```python # FreezeGun freezer = freeze_time("2023-01-01") freezer.start() freezer.move_to("2023-01-02") freezer.stop() ``` -------------------------------- ### Initialize Codebase with Custom Configuration Source: https://github.com/codegen-sh/graph-sitter/blob/develop/docs/introduction/advanced-settings.mdx Demonstrates how to initialize a Codebase instance with custom configuration flags by passing a CodebaseConfig object. ```python from graph_sitter import Codebase from graph_sitter.configs import CodebaseConfig # Initialize a Codebase with custom configuration codebase = Codebase( "", config=CodebaseConfig( flag1=..., flag2=..., ... ) ) ``` -------------------------------- ### Convert unittest Test Class to Pytest Function Source: https://github.com/codegen-sh/graph-sitter/blob/develop/docs/tutorials/unittest-to-pytest.mdx Converts a unittest.TestCase class with setUp and tearDown methods to a pytest function-based test using fixtures. Ensure pytest is installed and imported. ```python # From: class TestUsers(unittest.TestCase): def setUp(self): self.db = setup_test_db() def tearDown(self): self.db.cleanup() def test_create_user(self): user = self.db.create_user("test") self.assertEqual(user.name, "test") # To: import pytest @pytest.fixture def db(): db = setup_test_db() yield db db.cleanup() def test_create_user(db): user = db.create_user("test") assert user.name == "test" ``` -------------------------------- ### Initialize Codebase with Configuration Source: https://github.com/codegen-sh/graph-sitter/blob/develop/docs/graph-sitter/getting-started.mdx Import necessary classes for initializing a Codebase with custom configurations. ```python from graph_sitter import Codebase from graph_sitter.configs import CodebaseConfig ``` -------------------------------- ### Convert unittest Class Setup to Pytest Fixtures Source: https://github.com/codegen-sh/graph-sitter/blob/develop/docs/tutorials/unittest-to-pytest.mdx Migrates unittest's class-level and method-level setup/teardown methods to pytest fixtures with appropriate scopes. This example shows session-scoped and function-scoped fixtures for database connections and transactions. ```python # From: class TestDatabase(unittest.TestCase): @classmethod def setUpClass(cls): cls.db_conn = create_test_db() def setUp(self): self.transaction = self.db_conn.begin() def tearDown(self): self.transaction.rollback() # To: @pytest.fixture(scope="session") def db_conn(): return create_test_db() @pytest.fixture def transaction(db_conn): transaction = db_conn.begin() yield transaction transaction.rollback() ``` -------------------------------- ### Basic MCP Server Setup Source: https://github.com/codegen-sh/graph-sitter/blob/develop/src/graph_sitter/system-prompt.txt Initializes a basic MCP server using Codegen's FastMCP and imports necessary components from the graph_sitter library. ```python from graph_sitter import Codebase from mcp.server.fastmcp import FastMCP from typing import Annotated ``` -------------------------------- ### Basic Setup for Codebase Visualization Source: https://github.com/codegen-sh/graph-sitter/blob/develop/docs/tutorials/codebase-visualization.mdx Initializes the Codebase, a directed graph for call relationships, and configuration flags for filtering and coloring nodes. Required for building visualizations. ```python import networkx as nx from graph_sitter import Codebase # Initialize codebase codebase = Codebase("path/to/posthog/") # Create a directed graph for representing call relationships G = nx.DiGraph() # Configuration flags IGNORE_EXTERNAL_MODULE_CALLS = True # Skip calls to external modules IGNORE_CLASS_CALLS = False # Include class definition calls MAX_DEPTH = 10 COLOR_PALETTE = { "StartFunction": "#9cdcfe", # Light blue - Start Function "PyFunction": "#a277ff", # Soft purple/periwinkle - PyFunction "PyClass": "#ffca85", # Warm peach/orange - PyClass "ExternalModule": "#f694ff" # Bright magenta/pink - ExternalModule } ``` -------------------------------- ### Launch Jupyter Notebook with Demo Source: https://github.com/codegen-sh/graph-sitter/blob/develop/docs/graph-sitter/getting-started.mdx Launch a Jupyter notebook environment pre-configured with a demo codebase for quick prototyping. ```bash gs notebook --demo ``` -------------------------------- ### Behavior Combinations Example Source: https://github.com/codegen-sh/graph-sitter/blob/develop/src/graph_sitter/system-prompt.txt Example demonstrating how multiple behaviors can be combined on a single code element. ```APIDOC ## Behavior Combinations Many code elements inherit multiple behaviors. For example, a function typically has: ```python # Functions combine multiple behaviors function = codebase.get_function("process_data") # HasName behavior print(function.name) function.rename("process_input") # HasBlock behavior print(len(function.code_block.statements)) function.add_decorator("@timer") # Editable behavior function.edit("def process_input():\n pass") ``` ``` -------------------------------- ### Install graph-sitter CLI Source: https://github.com/codegen-sh/graph-sitter/blob/develop/docs/blog/devin.mdx Install the graph_sitter CLI tool for your Python environment to enable codemod functionality. ```bash uv tool install graph-sitter --python 3.13 ``` -------------------------------- ### Install Graph-sitter with Pipx Source: https://github.com/codegen-sh/graph-sitter/blob/develop/docs/graph-sitter/overview.mdx Install the graph-sitter tool using Pipx. Note that Pipx is not officially supported by Codegen. ```bash pipx install graph-sitter ``` -------------------------------- ### Install UV Package Manager on macOS Source: https://github.com/codegen-sh/graph-sitter/blob/develop/CONTRIBUTING.md Use Homebrew to install the UV package manager on macOS systems. ```bash brew install uv ``` -------------------------------- ### Initialize Codebase from Local Path Source: https://github.com/codegen-sh/graph-sitter/blob/develop/docs/graph-sitter/getting-started.mdx Instantiate a Codebase object by parsing a local Git repository. ```python codebase = Codebase("path/to/git/repo") ``` -------------------------------- ### Initialize Graph-sitter Project Source: https://github.com/codegen-sh/graph-sitter/blob/develop/docs/building-with-graph-sitter/dot-codegen.mdx Use this command to initialize a new Graph-sitter project, creating the .codegen directory and its essential files. Optional arguments allow specifying the repository and organization names. ```bash gs init [--repo-name NAME] [--organization-name ORG] ``` -------------------------------- ### Initialize Codebase and MCP Server Source: https://github.com/codegen-sh/graph-sitter/blob/develop/src/graph_sitter/system-prompt.txt Initializes the codebase from a repository and creates an MCP server instance with specified instructions. The server is then run using stdio transport. ```python codebase = Codebase.from_repo(".") # create the MCP server using FastMCP mcp = FastMCP(name="demo-mcp", instructions="Use this server for semantic search of codebases") if __name__ == "__main__": # Initialize and run the server print("Starting demo mpc server...") mcp.run(transport="stdio") ``` -------------------------------- ### Install and Run Dead Code Removal Script Source: https://github.com/codegen-sh/graph-sitter/blob/develop/examples/examples/delete_dead_code/README.md Installs the Graph-sitter library and executes the Python script for dead code removal. ```bash # Install Graph-sitter pip install graph-sitter # Run the script python run.py ``` -------------------------------- ### Accessing Files and Directories Source: https://github.com/codegen-sh/graph-sitter/blob/develop/src/graph_sitter/system-prompt.txt Demonstrates how to get a file by its path, iterate over all files, and check for file existence. ```python # Get a file from the codebase file = codebase.get_file("path/to/file.py") ``` ```python # Iterate over all files in the codebase for file in codebase.files: pass ``` ```python # Check if a file exists exists = codebase.has_file("path/to/file.py") ``` -------------------------------- ### Structured Function Context JSON Example Source: https://github.com/codegen-sh/graph-sitter/blob/develop/docs/tutorials/training-data.mdx An example of the structured JSON output representing a function's implementation, dependencies, and usages. ```json { "implementation": { "source": "def process_data(input: str) -> dict: ...", "filepath": "src/data_processor.py" }, "dependencies": [ { "source": "def validate_input(data: str) -> bool: ...", "filepath": "src/validators.py" } ], "usages": [ { "source": "result = process_data(user_input)", "filepath": "src/api.py" } ] } ``` -------------------------------- ### Initialize Codebase from Repository Source: https://github.com/codegen-sh/graph-sitter/blob/develop/docs/graph-sitter/getting-started.mdx Instantiate a Codebase object by cloning and parsing a remote Git repository. ```python from graph_sitter import Codebase # Clone + parse fastapi/fastapi codebase = Codebase.from_repo('fastapi/fastapi') ``` -------------------------------- ### Initialize Component File Mapping (Python) Source: https://github.com/codegen-sh/graph-sitter/blob/develop/src/graph_sitter/system-prompt.txt Sets up a dictionary to store JSX components, keyed by their respective files, as a preliminary step for organizing components into individual files. ```python # Initialize a dictionary to store files and their corresponding JSX components files_with_jsx_components = {} ``` -------------------------------- ### Basic Chained Attribute Example Source: https://github.com/codegen-sh/graph-sitter/blob/develop/architecture/4. type-analysis/D. Chained Attributes.md Demonstrates a simple class definition and a chained attribute access. This serves as a foundational example for understanding chained attribute resolution. ```python class Foo: def foo(self): ... a = Foo() a.foo() ``` -------------------------------- ### Initialize Basic MCP Server Source: https://github.com/codegen-sh/graph-sitter/blob/develop/docs/tutorials/build-mcp.mdx Create a basic MCP server using FastMCP and initialize the codebase. The server runs using stdio transport. ```python from graph_sitter import Codebase from mcp.server.fastmcp import FastMCP from typing import Annotated # Initialize the codebase codebase = Codebase.from_repo(".") # create the MCP server using FastMCP mcp = FastMCP(name="demo-mcp", instructions="Use this server for semantic search of codebases") if __name__ == "__main__": # Initialize and run the server print("Starting demo mpc server...") mcp.run(transport="stdio") ``` -------------------------------- ### Codemod Command Usage Source: https://github.com/codegen-sh/graph-sitter/blob/develop/docs/cli/create.mdx This shows the general syntax for the `create` command, including required arguments and available options. ```bash gs create NAME PATH [OPTIONS] ``` -------------------------------- ### Initialize Codebase with Custom Configuration Source: https://github.com/codegen-sh/graph-sitter/blob/develop/docs/graph-sitter/getting-started.mdx Use this to initialize a Codebase with specific settings for analysis. Refer to the Advanced Settings page for a full list of available options. ```python codebase = Codebase( "path/to/git/repo"", config=CodebaseConfig( verify_graph=True, method_usages=False, sync_enabled=True, generics=False, import_resolution_overrides={ "old_module": "new_module" }, ts_language_engine=True, v8_ts_engine=True ) ) ``` -------------------------------- ### Python Generics Example Source: https://github.com/codegen-sh/graph-sitter/blob/develop/src/graph_sitter/system-prompt.txt Demonstrates Python code with generic type hints for a List class. This example is used to show the effect of the `generics` flag on type resolution. ```python class Point: def scale(cls, n: int): pass class List[T](): def pop(self) -> T: ... l: List[Point] = [] l.pop().scale(1) # Generic Usage ``` -------------------------------- ### Python Import Resolution Example Source: https://github.com/codegen-sh/graph-sitter/blob/develop/src/graph_sitter/system-prompt.txt A basic Python import example showing how a module `src.py` is imported as `operations` from a different directory structure. This is used to test the `import_resolution_paths` flag. ```python # a/b/c/src.py def update(): pass # consumer.py from c import src as operations operations.update() ``` -------------------------------- ### Utility Function Example in Python Source: https://github.com/codegen-sh/graph-sitter/blob/develop/examples/STRUCTURE.md Example of a utility function within a Graph-sitter project. It should have a clear docstring explaining its purpose and include type hints for better readability and maintainability. ```python def hop_through_imports(imp: Import) -> Symbol | ExternalModule: """Finds the root symbol for an import""" # Implementation... ``` -------------------------------- ### Advanced Initialization with ProjectConfig Source: https://github.com/codegen-sh/graph-sitter/blob/develop/docs/building-with-graph-sitter/parsing-codebases.mdx For complex scenarios, use `ProjectConfig` for fine-grained control over repository configuration, base path filtering, and multiple project setups. ```APIDOC ## Advanced Initialization with ProjectConfig ### Description For complex scenarios, use `ProjectConfig` for fine-grained control over repository configuration, base path filtering, and multiple project setups. ### Method `Codebase(projects: List[ProjectConfig])` ### Parameters #### Path Parameters - **projects** (List[ProjectConfig]) - Required - A list of `ProjectConfig` objects, each defining a project to be parsed. ### Request Example ```python from graph_sitter import Codebase from graph_sitter.git.repo_operator.local_repo_operator import LocalRepoOperator from graph_sitter.git.schemas.repo_config import BaseRepoConfig from graph_sitter.sdk.codebase.config import ProjectConfig codebase = Codebase( projects = [ ProjectConfig( repo_operator=LocalRepoOperator( repo_path="/tmp/codegen-sdk", repo_config=BaseRepoConfig(), bot_commit=True ), language="typescript", base_path="src/codegen/sdk/typescript", subdirectories=["src/codegen/sdk/typescript"] ) ] ) ``` ``` -------------------------------- ### Get and Access Directory Information Source: https://github.com/codegen-sh/graph-sitter/blob/develop/docs/building-with-graph-sitter/files-and-directories.mdx Retrieve a directory object using `codebase.get_directory()` and access its properties like name, path, and parent. You can also get specific files or subdirectories within it. ```python # Get a directory dir = codebase.get_directory("path/to/dir") ``` ```python # Access metadata name = dir.name # Directory name path = dir.path # Full path parent = dir.parent # Parent directory ``` ```python # Get specific items file = dir.get_file("file.py") subdir = dir.get_subdirectory("subdir") ``` ```python # Get all ancestor subdirectories subdirs = dir.subdirectories ``` ```python # Get the parent directory parent_dir = dir.parent ``` -------------------------------- ### Flask Route Decorator Example Source: https://github.com/codegen-sh/graph-sitter/blob/develop/src/graph_sitter/system-prompt.txt Illustrates the Flask-style route decorator syntax that the migration script targets. ```python @app.route("/users", methods=["POST"]) def create_user(): pass ``` -------------------------------- ### Modernize Class-Level Setup to pytest Fixtures Source: https://github.com/codegen-sh/graph-sitter/blob/develop/examples/examples/unittest_to_pytest/README.md Converts class-level setup methods (setUpClass) into session-scoped pytest fixtures. Use this to manage resources that need to be initialized once per test session. ```python # From: @classmethod def setUpClass(cls): cls.conn = create_db() # To: @pytest.fixture(scope="session") def conn(): return create_db() ``` -------------------------------- ### Configure Cursor MCP Server Source: https://github.com/codegen-sh/graph-sitter/blob/develop/src/graph_sitter/extensions/mcp/README.md Add this configuration in Cursor's MCP Servers settings to connect to the graph_sitter MCP server. Replace `` with the actual installation path. ```text Name: codegen-mcp Type: Command Command: uv --directory /codegen-sdk/src/graph_sitter.cli/mcp run ``` -------------------------------- ### Flask Template Rendering Example Source: https://github.com/codegen-sh/graph-sitter/blob/develop/docs/tutorials/flask-to-fastapi.mdx Illustrates the typical template rendering pattern in a Flask application. ```python @app.get("/users") def list_users(): return render_template("users.html", users=users) ``` -------------------------------- ### get_function Source: https://github.com/codegen-sh/graph-sitter/blob/develop/docs/api-reference/typescript/TSNamespace.mdx Get a function by name from this namespace. ```APIDOC ## get_function ### Description Get a function by name from this namespace. ### Response #### Success Response (200) - **TSFunction | None** - Returns the TSFunction if found, otherwise None. ``` -------------------------------- ### Initialize and Run Agent with Graph-sitter SDK Source: https://github.com/codegen-sh/graph-sitter/blob/develop/docs/introduction/api.mdx Initialize an Agent with your organization ID and API token, then run a task with a prompt. Check the task status and refresh it for updates. The result may contain code, summaries, or links. ```python from graph_sitter import Agent # Initialize the Agent with your organization ID and API token agent = Agent(org_id="...", token="...") # Run an agent with a prompt task = agent.run(prompt="Leave a review on PR #123") # Check the initial status print(task.status) # Refresh the task to get updated status (tasks can take time) task.refresh() if task.status == "completed": print(task.result) # Result often contains code, summaries, or links ``` -------------------------------- ### get_enum Source: https://github.com/codegen-sh/graph-sitter/blob/develop/docs/api-reference/typescript/TSNamespace.mdx Get an enum by name from this namespace. ```APIDOC ## get_enum ### Description Get an enum by name from this namespace. ### Response #### Success Response (200) - **TSEnum | None** - Returns the TSEnum if found, otherwise None. ``` -------------------------------- ### get_class Source: https://github.com/codegen-sh/graph-sitter/blob/develop/docs/api-reference/typescript/TSNamespace.mdx Get a class by name from this namespace. ```APIDOC ## get_class ### Description Get a class by name from this namespace. ### Response #### Success Response (200) - **TSClass | None** - Returns the TSClass if found, otherwise None. ``` -------------------------------- ### List Supported Graph-sitter Versions Source: https://github.com/codegen-sh/graph-sitter/blob/develop/docs/cli/update.mdx Use this command to see a list of all versions of Graph-sitter that are available for installation from PyPI. The current version is highlighted. ```bash gs update --list ``` -------------------------------- ### value Source: https://github.com/codegen-sh/graph-sitter/blob/develop/docs/api-reference/typescript/TSExport.mdx Gets the value node of the object. ```APIDOC ## value ### Description Gets the value node of the object. ### Type Expression | None ```