View Source on Github
Attributes
classes
List of all Classes in the codebase.
codeowners
List all CodeOnwers in the codebase.
current_commit
GitCommit | None
default_branch
str
directories
List all directories in the codebase.
exports
Returns a list of all Export nodes in the codebase.
external_modules
Returns a list of all external modules in the codebase.
functions
List of all Functions in the codebase.
github
RepoOperator
global_vars
List of all GlobalVars in the codebase.
imports
Returns a list of all Import nodes in the codebase.
interfaces
Retrieves all interfaces in the codebase.
language
ProgrammingLanguage
name
str
repo_path
Path
symbols
List of all top-level Symbols (Classes, Functions, etc.) in the codebase. Excludes Class
types
List of all Types in the codebase (Typescript only).
Methods
ai
Generates a response from the AI based on the provided prompt, target, and context.View Source on Github
Parameters
prompt
str
required
target
Editable | None
default:None
Additional context to help inform the AI's response.
model
str
default:"gpt-4o"
Returns
str
checkout
Checks out a git branch or commit and syncs the codebase graph to the new state.View Source on Github
Parameters
commit
str | GitCommit | None
default:None
branch
str | None
default:None
create_if_missing
bool
default:False
remote
bool
default:False
Returns
CheckoutResult
commit
Commits all staged changes to the codebase graph and synchronizes the graph with the filesystem if specified.View Source on Github
Parameters
sync_graph
bool
default:True
Returns
None
create_directory
Creates a directory at the specified path.View Source on Github
Parameters
dir_path
str
required
exist_ok
bool
default:False
parents
bool
default:False
Returns
None
create_file
Creates a new file in the codebase with specified content.View Source on Github
Parameters
filepath
str
required
content
str
default:""
sync
bool
default:True
Returns
The newly created file object.
create_pr
Creates a pull request from the current branch to the repository’s default branch.View Source on Github
Parameters
title
str
required
body
str
required
Returns
PullRequest
create_pr_comment
Create a comment on a pull requestView Source on Github
Returns
None
create_pr_review_comment
Create a review comment on a pull request.View Source on Github
Returns
None
files
A list property that returns all files in the codebase.View Source on Github
Returns
A sorted list of source files in the codebase.
find_by_span
Finds editable objects that overlap with the given source code span.View Source on Github
Parameters
span
required
Returns
A list of Editable objects that overlap with the given span.
from_files
Creates a Codebase instance from multiple files.View Source on Github
Returns
A Codebase instance initialized with the provided files
from_repo
Fetches a codebase from GitHub and returns a Codebase instance.View Source on Github
Parameters
repo_name
str
required
tmp_dir
Optional[str]
default:"/tmp/codegen"
commit
Optional[str]
default:None
shallow
bool
required
language
Literal["python", "typescript"] | ProgrammingLanguage | None
required
config
CodebaseConfig
required
secrets
SecretsConfig
required
Returns
A Codebase instance initialized with the cloned repository
from_string
Creates a Codebase instance from a string of code.View Source on Github
Returns
A Codebase instance initialized with the provided code Example: >>> # Python code >>> code = "def add(a, b): return a + b" >>> codebase = Codebase.from_string(code, language="python") >>> # TypeScript code >>> code = "function add(a: number, b: number): number { return a + b; }" >>> codebase = Codebase.from_string(code, language="typescript")
get_class
Returns a class that matches the given name.View Source on Github
Parameters
class_name
str
required
optional
bool
default:False
Returns
Class | None
get_directory
Returns Directory bydir_path
, or full path to the directory from codebase root.
View Source on Github
Parameters
dir_path
str
required
optional
bool
default:False
Returns
Directory | None
get_file
Retrieves a file from the codebase by its filepath.View Source on Github
Parameters
filepath
str
required
optional
bool
default:False
ignore_case
bool
default:False
Returns
SourceFile | None
get_function
Retrieves a function from the codebase by its name.View Source on Github
Parameters
function_name
str
required
optional
bool
default:False
Returns
Function | None
get_modified_symbols_in_pr
Get all modified symbols in a pull requestView Source on Github
Returns
tuple[str, dict[str, str], list[str], str]
get_relative_path
Calculates a relative path from one file to another, removing the extension from the target file.View Source on Github
Parameters
from_file
str
required
to_file
str
required
Returns
str
get_symbol
Returns a Symbol by name from the codebase.View Source on Github
Parameters
symbol_name
str
required
optional
bool
default:False
Returns
Symbol | None
get_symbols
Retrieves all symbols in the codebase that match the given symbol name.View Source on Github
Parameters
symbol_name
str
required
Returns
A list of Symbol objects that match the given name, sorted alphabetically.
git_commit
Stages + commits all changes to the codebase and git.View Source on Github
Parameters
message
str
required
verify
bool
default:False
Returns
GitCommit | None
has_directory
Returns a boolean indicating if a directory exists in the codebase.View Source on Github
Parameters
dir_path
str
required
Returns
bool
has_file
Determines if a file exists in the codebase.View Source on Github
Parameters
filepath
str
required
ignore_case
bool
default:False
Returns
bool
has_symbol
Returns whether a symbol exists in the codebase.View Source on Github
Parameters
symbol_name
str
required
Returns
bool
reset
Resets the codebase byView Source on Github
Returns
None
set_ai_key
Sets the OpenAI key for the current Codebase instance.View Source on Github
Returns
None
set_session_options
Sets the session options for the current codebase.View Source on Github
Parameters
max_transactions
int, optional
required
max_seconds
int, optional
required
max_ai_requests
int, optional
required
Returns
None
should_fix
Returns True if the flag should be fixed based on the current mode and active group.View Source on Github
Parameters
flag
CodeFlag
required
Returns
bool
visualize
Visualizes a NetworkX graph or Plotly figure.View Source on Github
Parameters
G
Graph | go.Figure
required
root
Editable | str | int | None
default:None
Returns
None