> ## Documentation Index
> Fetch the complete documentation index at: https://codegeninc-codegen-bot-sdk-docs-2-0.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# SourceFile

> Represents a file with source code in the codebase. Enables creating, reading, updating, and deleting files and searching through their contents, etc.

export const Attribute = ({type, description}) => <div className="pl-4 py-6 first:pt-3 dark:border-zinc-300/[0.06] text-sm font-normal">
    <div className="inline-grid grid-cols-[auto_auto] gap-1 font-mono py-2">
      {type}
    </div>
    <p className="mt-2">{description}</p>
  </div>;

export const GithubLinkNote = ({link}) => <Info>
      <div className="flex gap-2 items-center">View Source on <a target="_blank" rel="noopener noreferrer" href={link}>Github</a></div>
   </Info>;

export const HorizontalDivider = ({light = false}) => <div className="divide-y">
        <div className={`divide-y ${light ? "dark:border-zinc-300/[0.06]" : "border-zinc-600"}`}></div>
        <div className={`divide-y ${light ? "dark:border-zinc-300/[0.06]" : "border-zinc-600"}`}></div>
    </div>;

export const Return = ({return_type, description}) => <div className="pl-6 divide-y">
    <h4 className="font-bold">Returns</h4>
    <div className="dark:border-zinc-300/[0.06] ">
        <div className="py-6 first:pt-3 text-sm font-normal">
            <div className="flex gap-4 items-center">
                <div className="inline-grid grid-cols-[auto_auto] gap-1 font-mono py-2">
                    {return_type}
                </div>
            </div>
            <p className="mt-2">{description}</p>
        </div>
    </div>
  </div>;

export const ParameterWrapper = ({children}) => <div className="pl-6 divide-y">
    <h4 className="font-bold">Parameters</h4>
    <div className="divide-y dark:border-zinc-300/[0.06]">
      {children}
    </div>
  </div>;

export const Parameter = ({name, type, description, defaultValue}) => <div className="py-6 first:pt-3 dark:border-zinc-300/[0.06] text-sm font-normal">
    <div className="flex justify-between items-start font-mono">
      <div className="flex gap-4 items-start">
        <div className="flex gap-1 items-center text-sm text-primary mt-2">
          {name}
        </div>
        <div className="inline-grid grid-cols-[auto_auto] gap-1 py-2">
          {type}
        </div>
      </div>

      <div className="flex-shrink-0 mt-2">
        {defaultValue ? <div className="flex gap-1 items-center text-sm border border-purple-500 px-2 py-0.5 rounded">
            <span className="text-zinc-500">default:</span>
            <span className="text-purple-500">{defaultValue}</span>
          </div> : <span className="text-sm border border-purple-500 px-2 py-0.5 rounded">
            required
          </span>}
      </div>
    </div>
    <p className="mt-2">{description}</p>
  </div>;

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/file.py#L412-L1190" />

### Inherits from

[Usable](/api-reference/core/Usable), [HasBlock](/api-reference/core/HasBlock), [File](/api-reference/core/File), [Importable](/api-reference/core/Importable), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable), [HasName](/api-reference/core/HasName)

## Attributes

<HorizontalDivider />

### <span className="text-primary">classes</span>

<HorizontalDivider light={true} />

<Attribute type={ <><span>list[</span> <a href="/api-reference/core/Class" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Class</a> <span>]</span></> } description="Returns all Classes in the file." />

### <span className="text-primary">code\_block</span>

<HorizontalDivider light={true} />

<Attribute type={ <><a href="/api-reference/core/CodeBlock" style={ {fontWeight: "inherit", fontSize: "inherit"} }>CodeBlock</a></> } description="Represents the block of code contained in the file." />

### <span className="text-primary">content</span>

<HorizontalDivider light={true} />

<Attribute type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="Returns the content of the file as a UTF-8 encoded string." />

### <span className="text-primary">decorators</span>

<HorizontalDivider light={true} />

<Attribute type={ <><span>list[</span> <a href="/api-reference/core/Decorator" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Decorator</a> <span>]</span></> } description="Returns list of all decorators on this Symbol." />

### <span className="text-primary">directory</span>

<HorizontalDivider light={true} />

<Attribute type={ <><a href="/api-reference/core/Directory" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Directory</a> <span>| None</span></> } description="Returns the directory that contains this file." />

### <span className="text-primary">docstring</span>

<HorizontalDivider light={true} />

<Attribute type={ <><a href="/api-reference/core/CommentGroup" style={ {fontWeight: "inherit", fontSize: "inherit"} }>CommentGroup</a> <span>| None</span></> } description="Retrieves the docstring of the expression." />

### <span className="text-primary">extended</span>

<HorizontalDivider light={true} />

<Attribute type={ <><a href="/api-reference/core/SymbolGroup" style={ {fontWeight: "inherit", fontSize: "inherit"} }>SymbolGroup</a></> } description="Returns a SymbolGroup of all extended nodes associated with this element." />

### <span className="text-primary">extended\_source</span>

<HorizontalDivider light={true} />

<Attribute type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="Returns the source text representation of all extended nodes." />

### <span className="text-primary">extension</span>

<HorizontalDivider light={true} />

<Attribute type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="Returns the file extension." />

### <span className="text-primary">file</span>

<HorizontalDivider light={true} />

<Attribute type={ <><a href="/api-reference/core/SourceFile" style={ {fontWeight: "inherit", fontSize: "inherit"} }>SourceFile</a></> } description="A property that returns the file object for non-source files." />

### <span className="text-primary">file\_path</span>

<HorizontalDivider light={true} />

<Attribute type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The relative file path as a string." />

### <span className="text-primary">filepath</span>

<HorizontalDivider light={true} />

<Attribute type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="Retrieves the file path of the file that this Editable instance belongs to." />

### <span className="text-primary">full\_name</span>

<HorizontalDivider light={true} />

<Attribute type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str | None</code> } description="Returns the full name of the object, including the namespace path." />

### <span className="text-primary">function\_calls</span>

<HorizontalDivider light={true} />

<Attribute type={ <><span>list[</span> <a href="/api-reference/core/FunctionCall" style={ {fontWeight: "inherit", fontSize: "inherit"} }>FunctionCall</a> <span>]</span></> } description="Returns all function calls within the code block and its decorators." />

### <span className="text-primary">functions</span>

<HorizontalDivider light={true} />

<Attribute type={ <><span>list[</span> <a href="/api-reference/core/Function" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Function</a> <span>]</span></> } description="Returns all Functions in the file." />

### <span className="text-primary">global\_vars</span>

<HorizontalDivider light={true} />

<Attribute type={ <><span>list[</span> <a href="/api-reference/core/Assignment" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Assignment</a> <span>]</span></> } description="Returns all GlobalVars in the file." />

### <span className="text-primary">import\_module\_name</span>

<HorizontalDivider light={true} />

<Attribute type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="Returns the module name that this file gets imported as." />

### <span className="text-primary">import\_statements</span>

<HorizontalDivider light={true} />

<Attribute type={ <><span>list[</span> <a href="/api-reference/core/ImportStatement" style={ {fontWeight: "inherit", fontSize: "inherit"} }>ImportStatement</a> <span>]</span></> } description="Returns all ImportStatements in the file, where each import statement can contain" />

### <span className="text-primary">importers</span>

<HorizontalDivider light={true} />

<Attribute type={ <><span>list[</span> <a href="/api-reference/core/Import" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Import</a> <span>]</span></> } description="Returns all imports that directly imports this file as a module." />

### <span className="text-primary">imports</span>

<HorizontalDivider light={true} />

<Attribute type={ <><span>list[</span> <a href="/api-reference/core/Import" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Import</a> <span>]</span></> } description="List of all Imports in this file." />

### <span className="text-primary">inbound\_imports</span>

<HorizontalDivider light={true} />

<Attribute type={ <><span>list[</span> <a href="/api-reference/core/Import" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Import</a> <span>]</span></> } description="Returns all imports that are importing symbols contained in this file." />

### <span className="text-primary">is\_binary</span>

<HorizontalDivider light={true} />

<Attribute type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="Indicates whether the file contains binary data." />

### <span className="text-primary">is\_decorated</span>

<HorizontalDivider light={true} />

<Attribute type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="Check if the symbol has decorators." />

### <span className="text-primary">name</span>

<HorizontalDivider light={true} />

<Attribute type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str | None</code> } description="Retrieves the base name of the object without namespace prefixes." />

### <span className="text-primary">owners</span>

<HorizontalDivider light={true} />

<Attribute type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">set[str]</code> } description="Returns the CODEOWNERS of the file." />

### <span className="text-primary">parent</span>

<HorizontalDivider light={true} />

<Attribute type={ <><a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a></> } description="The parent node of this Editable instance." />

### <span className="text-primary">parent\_class</span>

<HorizontalDivider light={true} />

<Attribute type={ <><a href="/api-reference/core/Class" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Class</a> <span>| None</span></> } description="Find the class this node is contained in" />

### <span className="text-primary">parent\_function</span>

<HorizontalDivider light={true} />

<Attribute type={ <><a href="/api-reference/core/Function" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Function</a> <span>| None</span></> } description="Find the function this node is contained in" />

### <span className="text-primary">parent\_statement</span>

<HorizontalDivider light={true} />

<Attribute type={ <><a href="/api-reference/core/Statement" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Statement</a> <span>| None</span></> } description="Find the statement this node is contained in" />

### <span className="text-primary">path</span>

<HorizontalDivider light={true} />

<Attribute type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">Path</code> } description="The absolute path of the file as a Path object." />

### <span className="text-primary">resolved\_value</span>

<HorizontalDivider light={true} />

<Attribute type={ <><a href="/api-reference/core/Expression" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Expression</a> <span>| list[</span> <a href="/api-reference/core/Expression" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Expression</a> <span>]</span></> } description="Returns the resolved type of an Expression." />

### <span className="text-primary">source</span>

<HorizontalDivider light={true} />

<Attribute type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="Text representation of the Editable instance." />

### <span className="text-primary">start\_byte</span>

<HorizontalDivider light={true} />

<Attribute type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">int</code> } description="Returns the starting byte position of a file in its content." />

### <span className="text-primary">symbols\_sorted\_topologically</span>

<HorizontalDivider light={true} />

<Attribute type={ <><span>list[</span> <a href="/api-reference/core/Symbol" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Symbol</a> <span>]</span></> } description="Returns all Symbols in the file, sorted topologically (parents first). Robust to" />

### <span className="text-primary">variable\_usages</span>

<HorizontalDivider light={true} />

<Attribute type={ <><span>list[</span> <a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>]</span></> } description="Returns Editables for all TreeSitter node instances of variable usages within this node's" />

## Methods

<HorizontalDivider />

### <span className="text-primary">add\_decorator</span>

Adds a decorator to a function or method.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/interfaces/has_block.py#L97-L119" />

<ParameterWrapper>
  <Parameter name="new_decorator" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The decorator to add, including the '@' symbol." defaultValue="" />

  <Parameter name="skip_if_exists" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool, optional</code> } description="If True, skips adding if the decorator exists." defaultValue="False" />
</ParameterWrapper>

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="True if the decorator was added, False if skipped." />

### <span className="text-primary">add\_import</span>

Adds an import to the file.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/file.py#L975-L1023" />

<ParameterWrapper>
  <Parameter name="imp" type={ <><a href="/api-reference/core/Symbol" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Symbol</a> <span>| str</span></> } description="Either a Symbol to import or a string representation of an import statement." defaultValue="" />

  <Parameter name="alias" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str | None</code> } description="Optional alias for the imported symbol. Only used when imp is a Symbol. Defaults to None." defaultValue="None" />

  <Parameter name="import_type" type={ <><a href="/api-reference/core/ImportType" style={ {fontWeight: "inherit", fontSize: "inherit"} }>ImportType</a></> } description="The type of import to use. Only used when imp is a Symbol. Defaults to ImportType.UNKNOWN." defaultValue="ImportType.UNKNOWN" />

  <Parameter name="is_type_import" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="Whether this is a type-only import. Only used when imp is a Symbol. Defaults to False." defaultValue="False" />
</ParameterWrapper>

<Return return_type={ <><a href="/api-reference/core/Import" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Import</a> <span>| None</span></> } description="The existing import for the symbol if found, otherwise None." />

### <span className="text-primary">add\_symbol</span>

Adds `symbol` to the file.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/file.py#L1046-L1077" />

<ParameterWrapper>
  <Parameter name="symbol" type={ <><a href="/api-reference/core/Symbol" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Symbol</a></> } description="The symbol to add to the file." defaultValue="" />

  <Parameter name="should_export" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool, optional</code> } description="Whether to export the symbol. Defaults to True." defaultValue="True" />
</ParameterWrapper>

<Return return_type={ <><a href="/api-reference/core/Symbol" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Symbol</a> <span>| None</span></> } description="The existing symbol if it already exists in the file or None if it was added." />

### <span className="text-primary">add\_symbol\_from\_source</span>

Adds a symbol to a file from a string representation.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/file.py#L1026-L1043" />

<ParameterWrapper>
  <Parameter name="source" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="String representation of the symbol to be added. This should be valid source code for" defaultValue="" />
</ParameterWrapper>

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">None</code> } description="The symbol is added directly to the file's content." />

### <span className="text-primary">ancestors</span>

Find all ancestors of the node of the given type. Does not return itself

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/interfaces/editable.py#L1119-L1127" />

<Return return_type={ <><span>list[</span> <a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>]</span></> } description="" />

### <span className="text-primary">dependencies</span>

Returns a list of symbols that this symbol depends on.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/interfaces/importable.py#L46-L78" />

<ParameterWrapper>
  <Parameter name="usage_types" type={ <><a href="/api-reference/core/UsageType" style={ {fontWeight: "inherit", fontSize: "inherit"} }>UsageType</a> <span>| None</span></> } description="The types of dependencies to search for. Defaults to UsageType.DIRECT." defaultValue="UsageType.DIRECT" />

  <Parameter name="max_depth" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">int | None</code> } description="Maximum depth to traverse in the dependency graph. If provided, will recursively collect" defaultValue="None" />
</ParameterWrapper>

<Return return_type={ <><span>list[Union[</span> <a href="/api-reference/core/Symbol" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Symbol</a> <span>,</span> <a href="/api-reference/core/Import" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Import</a> <span>]]</span></> } description="A list of symbols and imports that this symbol depends on, sorted by file location." />

### <span className="text-primary">edit</span>

Replace the source of this file with new\_src.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/file.py#L330-L357" />

<ParameterWrapper>
  <Parameter name="new_src" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The new source text to replace the current text with." defaultValue="" />

  <Parameter name="fix_indentation" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="If True, adjusts the indentation of new_src to match the current" defaultValue="False" />

  <Parameter name="priority" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">int</code> } description="The priority of the edit transaction. Higher priority edits are" defaultValue="0" />

  <Parameter name="dedupe" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="If True, deduplicates identical transactions. Defaults to True." defaultValue="True" />
</ParameterWrapper>

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">None</code> } description="" />

### <span className="text-primary">find</span>

Find and return matching nodes or substrings within an Editable instance.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/interfaces/editable.py#L487-L504" />

<ParameterWrapper>
  <Parameter name="strings_to_match" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">Union[list[str], str]</code> } description="One or more strings to search for." defaultValue="" />

  <Parameter name="exact" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="If True, only return nodes whose source exactly matches one of the strings_to_match." defaultValue="False" />
</ParameterWrapper>

<Return return_type={ <><span>list[</span> <a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>]</span></> } description="A list of Editable instances that match the search criteria." />

### <span className="text-primary">find\_by\_byte\_range</span>

Finds all editable objects that overlap with the given byte range in the file.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/file.py#L1173-L1185" />

<ParameterWrapper>
  <Parameter name="range" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">Range</code> } description="The byte range to search within the file." defaultValue="" />
</ParameterWrapper>

<Return return_type={ <><span>list[</span> <a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>]</span></> } description="A list of all Editable objects that overlap with the given range." />

### <span className="text-primary">find\_string\_literals</span>

Returns a list of string literals within this node's source that match any of the given

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/interfaces/editable.py#L398-L412" />

<ParameterWrapper>
  <Parameter name="strings_to_match" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">list[str]</code> } description="A list of strings to search for in string literals." defaultValue="" />

  <Parameter name="fuzzy_match" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="If True, matches substrings within string literals. If False, only matches exact strings. Defaults to False." defaultValue="False" />
</ParameterWrapper>

<Return return_type={ <><span>list[</span> <a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>[</span> <a href="/api-reference/core/SourceFile" style={ {fontWeight: "inherit", fontSize: "inherit"} }>SourceFile</a> <span>]]</span></> } description="A list of Editable objects representing the matching string literals." />

### <span className="text-primary">flag</span>

Adds a visual flag comment to the end of this Editable's source text.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/interfaces/editable.py#L939-L950" />

<Return return_type={ <><span>CodeFlag[</span> <a href="/api-reference/core/SourceFile" style={ {fontWeight: "inherit", fontSize: "inherit"} }>SourceFile</a> <span>]</span></> } description="" />

### <span className="text-primary">get\_class</span>

Returns a specific Class by full name. Returns None if not found.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/file.py#L811-L824" />

<ParameterWrapper>
  <Parameter name="name" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The full name of the class to search for." defaultValue="" />
</ParameterWrapper>

<Return return_type={ <><a href="/api-reference/core/Class" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Class</a> <span>| None</span></> } description="The matching Class object if found, None otherwise." />

### <span className="text-primary">get\_function</span>

Returns a specific Function by name.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/file.py#L840-L851" />

<ParameterWrapper>
  <Parameter name="name" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The name of the function to find." defaultValue="" />
</ParameterWrapper>

<Return return_type={ <><a href="/api-reference/core/Function" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Function</a> <span>| None</span></> } description="The matching Function object if found, None otherwise." />

### <span className="text-primary">get\_global\_var</span>

Returns a specific global var by name. Returns None if not found.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/file.py#L786-L795" />

<ParameterWrapper>
  <Parameter name="name" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The name of the global variable to find." defaultValue="" />
</ParameterWrapper>

<Return return_type={ <><a href="/api-reference/core/Assignment" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Assignment</a> <span>| None</span></> } description="The global variable if found, None otherwise." />

### <span className="text-primary">get\_import</span>

Returns the import with matching alias. Returns None if not found.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/file.py#L697-L706" />

<ParameterWrapper>
  <Parameter name="symbol_alias" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The alias name to search for. This can match either the direct import name or the aliased name." defaultValue="" />
</ParameterWrapper>

<Return return_type={ <><a href="/api-reference/core/Import" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Import</a> <span>| None</span></> } description="The import statement with the matching alias if found, None otherwise." />

### <span className="text-primary">get\_name</span>

Returns the name node of the object.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/interfaces/has_name.py#L52-L62" />

<Return return_type={ <><a href="/api-reference/core/Name" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Name</a> <span>|</span> <a href="/api-reference/core/ChainedAttribute" style={ {fontWeight: "inherit", fontSize: "inherit"} }>ChainedAttribute</a> <span>| None</span></> } description="The name node of the object. Can be a Name node for simple names, a ChainedAttribute for names with namespaces (e.g., a.b), or None if the object has no name." />

### <span className="text-primary">get\_symbol</span>

Gets a symbol by its name from the file.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/file.py#L735-L750" />

<ParameterWrapper>
  <Parameter name="name" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The name of the symbol to find." defaultValue="" />
</ParameterWrapper>

<Return return_type={ <><a href="/api-reference/core/Symbol" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Symbol</a> <span>| None</span></> } description="The found symbol, or None if not found." />

### <span className="text-primary">get\_variable\_usages</span>

Returns Editables for all TreeSitter nodes corresponding to instances of variable usage

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/interfaces/editable.py#L909-L925" />

<ParameterWrapper>
  <Parameter name="var_name" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The variable name to search for." defaultValue="" />

  <Parameter name="fuzzy_match" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="If True, matches variables where var_name is a substring. If False, requires exact match. Defaults to False." defaultValue="False" />
</ParameterWrapper>

<Return return_type={ <><span>Sequence[</span> <a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>[</span> <a href="/api-reference/core/SourceFile" style={ {fontWeight: "inherit", fontSize: "inherit"} }>SourceFile</a> <span>]]</span></> } description="List of Editable objects representing variable usage nodes matching the given name." />

### <span className="text-primary">has\_import</span>

Returns True if the file has an import with the given alias.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/file.py#L682-L694" />

<ParameterWrapper>
  <Parameter name="symbol_alias" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The alias to check for in the import statements." defaultValue="" />
</ParameterWrapper>

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="True if an import with the given alias exists, False otherwise." />

### <span className="text-primary">insert\_after</span>

Inserts code after this node.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/interfaces/editable.py#L608-L634" />

<ParameterWrapper>
  <Parameter name="new_src" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The source code to insert after this node." defaultValue="" />

  <Parameter name="fix_indentation" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool, optional</code> } description="Whether to adjust the indentation of new_src to match the current node. Defaults to False." defaultValue="False" />

  <Parameter name="newline" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool, optional</code> } description="Whether to add a newline before the new_src. Defaults to True." defaultValue="True" />

  <Parameter name="priority" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">int, optional</code> } description="Priority of the insertion transaction. Defaults to 0." defaultValue="0" />

  <Parameter name="dedupe" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool, optional</code> } description="Whether to deduplicate identical transactions. Defaults to True." defaultValue="True" />
</ParameterWrapper>

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">None</code> } description="" />

### <span className="text-primary">insert\_before</span>

Inserts text before this node's source with optional indentation and newline handling.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/interfaces/editable.py#L575-L605" />

<ParameterWrapper>
  <Parameter name="new_src" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The text to insert before this node." defaultValue="" />

  <Parameter name="fix_indentation" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="Whether to fix the indentation of new_src to match the current node. Defaults to False." defaultValue="False" />

  <Parameter name="newline" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="Whether to add a newline after new_src. Defaults to True." defaultValue="True" />

  <Parameter name="priority" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">int</code> } description="Transaction priority for managing multiple edits. Defaults to 0." defaultValue="0" />

  <Parameter name="dedupe" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="Whether to deduplicate identical transactions. Defaults to True." defaultValue="True" />
</ParameterWrapper>

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">None</code> } description="" />

### <span className="text-primary">is\_child\_of</span>

Checks if this node is a descendant of the given editable instance in the AST.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/interfaces/editable.py#L1109-L1116" />

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="" />

### <span className="text-primary">is\_wrapped\_in</span>

Check if this node is contained another node of the given class

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/interfaces/editable.py#L1088-L1090" />

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="" />

### <span className="text-primary">parent\_of\_type</span>

Find the first ancestor of the node of the given type. Does not return itself

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/interfaces/editable.py#L1093-L1099" />

<Return return_type={ <><a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>| None</span></> } description="" />

### <span className="text-primary">parent\_of\_types</span>

Find the first ancestor of the node of the given type. Does not return itself

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/interfaces/editable.py#L1101-L1107" />

<Return return_type={ <><a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>| None</span></> } description="" />

### <span className="text-primary">reduce\_condition</span>

Reduces an editable to the following condition

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/interfaces/editable.py#L1044-L1049" />

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">None</code> } description="" />

### <span className="text-primary">remove</span>

Removes the file from the file system and graph.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/file.py#L239-L251" />

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">None</code> } description="" />

### <span className="text-primary">remove\_unused\_exports</span>

Removes unused exports from the file.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/file.py#L937-L944" />

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">None</code> } description="" />

### <span className="text-primary">rename</span>

Renames a symbol and updates all its references in the codebase.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/interfaces/usable.py#L78-L91" />

<ParameterWrapper>
  <Parameter name="new_name" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The new name for the symbol." defaultValue="" />

  <Parameter name="priority" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">int</code> } description="Priority of the edit operation. Defaults to 0." defaultValue="0" />
</ParameterWrapper>

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">tuple[NodeId, NodeId]</code> } description="A tuple containing the file node ID and the new node ID of the renamed symbol." />

### <span className="text-primary">replace</span>

Replace occurrences of text in the file.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/file.py#L360-L394" />

<ParameterWrapper>
  <Parameter name="old" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The text to be replaced." defaultValue="" />

  <Parameter name="new" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The text to replace with." defaultValue="" />

  <Parameter name="count" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">int</code> } description="Maximum number of replacements to make. -1 means replace all occurrences." defaultValue="-1" />

  <Parameter name="is_regex" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="If True, treat 'old' as a regular expression pattern." defaultValue="False" />

  <Parameter name="priority" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">int</code> } description="The priority of the edit transaction. Higher priority edits are" defaultValue="0" />
</ParameterWrapper>

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">int</code> } description="List of affected Editable objects. For non-source files, always returns an empty list since they don't have Editable sub-components." />

### <span className="text-primary">search</span>

Returns a list of all regex match of `regex_pattern`, similar to python's re.search().

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/interfaces/editable.py#L520-L536" />

<ParameterWrapper>
  <Parameter name="regex_pattern" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The regular expression pattern to search for." defaultValue="" />

  <Parameter name="include_strings" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="When False, excludes the contents of string literals from the search. Defaults to True." defaultValue="True" />

  <Parameter name="include_comments" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="When False, excludes the contents of comments from the search. Defaults to True." defaultValue="True" />
</ParameterWrapper>

<Return return_type={ <><span>list[</span> <a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>]</span></> } description="A list of Editable objects corresponding to the matches found." />

### <span className="text-primary">set\_docstring</span>

Sets or updates the docstring for the current entity.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/interfaces/has_block.py#L136-L146" />

<ParameterWrapper>
  <Parameter name="docstring" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The new docstring content to set." defaultValue="" />
</ParameterWrapper>

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">None</code> } description="This method doesn't return anything." />

### <span className="text-primary">set\_name</span>

Sets the name of a code element.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/interfaces/has_name.py#L65-L77" />

<ParameterWrapper>
  <Parameter name="name" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The new name to set for the object." defaultValue="" />
</ParameterWrapper>

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">None</code> } description="" />

### <span className="text-primary">symbol\_can\_be\_added</span>

Checks if the file type supports adding the given symbol.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/file.py#L538-L549" />

<ParameterWrapper>
  <Parameter name="symbol" type={ <><a href="/api-reference/core/Symbol" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Symbol</a></> } description="The symbol to check for add compatibility." defaultValue="" />
</ParameterWrapper>

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="True if the symbol can be added to this file type, False otherwise." />

### <span className="text-primary">symbol\_usages</span>

Returns a list of symbols that use or import the exportable object.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/interfaces/usable.py#L27-L42" />

<ParameterWrapper>
  <Parameter name="usage_types" type={ <><a href="/api-reference/core/UsageType" style={ {fontWeight: "inherit", fontSize: "inherit"} }>UsageType</a> <span>| None</span></> } description="The types of usages to search for. Defaults to any." defaultValue="None" />
</ParameterWrapper>

<Return return_type={ <><span>list[</span> <a href="/api-reference/core/Import" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Import</a> <span>|</span> <a href="/api-reference/core/Symbol" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Symbol</a> <span>|</span> <a href="/api-reference/typescript/TSExport" style={ {fontWeight: "inherit", fontSize: "inherit"} }>TSExport</a> <span>]</span></> } description="A list of symbols that use or import the exportable object." />

### <span className="text-primary">symbols</span>

Returns all Symbols in the file, sorted by position in the file.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/file.py#L709-L723" />

<Return return_type={ <><span>list[</span> <a href="/api-reference/core/Symbol" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Symbol</a> <span>|</span> <a href="/api-reference/core/Class" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Class</a> <span>|</span> <a href="/api-reference/core/Function" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Function</a> <span>|</span> <a href="/api-reference/core/Assignment" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Assignment</a> <span>|</span> <a href="/api-reference/typescript/TSInterface" style={ {fontWeight: "inherit", fontSize: "inherit"} }>TSInterface</a> <span>]</span></> } description="A list of all top-level symbols in the file, sorted by their position in the file. Symbols can be one of the following types: - Symbol: Base symbol class - TClass: Class definition - TFunction: Function definition - TGlobalVar: Global variable assignment - TInterface: Interface definition" />

### <span className="text-primary">update\_filepath</span>

Renames the file and updates all imports to point to the new location.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/file.py#L951-L972" />

<ParameterWrapper>
  <Parameter name="new_filepath" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The new filepath to move the file to." defaultValue="" />
</ParameterWrapper>

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">None</code> } description="" />

### <span className="text-primary">usages</span>

Returns a list of usages of the exportable object.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/interfaces/usable.py#L46-L76" />

<ParameterWrapper>
  <Parameter name="usage_types" type={ <><a href="/api-reference/core/UsageType" style={ {fontWeight: "inherit", fontSize: "inherit"} }>UsageType</a> <span>| None</span></> } description="Specifies which types of usages to include in the results. Default is any usages." defaultValue="None" />
</ParameterWrapper>

<Return return_type={ <><span>list[</span> <a href="/api-reference/core/Usage" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Usage</a> <span>]</span></> } description="A sorted list of Usage objects representing where this exportable is used, ordered by source location in reverse." />
