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

# PyCodeBlock

> Extends CodeBlock for Python codebases.

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/python/detached_symbols/code_block.py#L23-L77" />

### Inherits from

[CodeBlock](/api-reference/core/CodeBlock), [Expression](/api-reference/core/Expression), [Editable](/api-reference/core/Editable)

## Attributes

<HorizontalDivider />

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

<HorizontalDivider light={true} />

<Attribute type={ <><span>list[</span> <a href="/api-reference/python/PyAssignmentStatement" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PyAssignmentStatement</a> <span>[</span> <a href="/api-reference/python/PyCodeBlock" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PyCodeBlock</a> <span>,</span> <a href="/api-reference/python/PyAssignment" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PyAssignment</a> <span>]]</span></> } description="Returns list of top level assignment statements in the code block." />

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

<HorizontalDivider light={true} />

<Attribute type={ <><span>list[</span> <a href="/api-reference/python/PyAssignment" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PyAssignment</a> <span>[</span> <a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>,</span> <a href="/api-reference/python/PyCodeBlock" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PyCodeBlock</a> <span>]]</span></> } description="Returns all assignments in the code block across all nesting levels." />

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

<HorizontalDivider light={true} />

<Attribute type={ <><span>list[</span> <a href="/api-reference/python/PyAttribute" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PyAttribute</a> <span>[</span> <a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>,</span> <a href="/api-reference/python/PyCodeBlock" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PyCodeBlock</a> <span>]]</span></> } description="Returns a list of top level class attribute statements in the code block." />

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

<HorizontalDivider light={true} />

<Attribute type={ <><span>list[</span> <a href="/api-reference/python/PyComment" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PyComment</a> <span>[</span> <a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>,</span> <a href="/api-reference/python/PyCodeBlock" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PyCodeBlock</a> <span>]]</span></> } description="Gets list of top level comments in the code block." />

### <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">file</span>

<HorizontalDivider light={true} />

<Attribute type={ <><a href="/api-reference/python/PyFile" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PyFile</a></> } description="The file object that this Editable instance belongs to." />

### <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="The file path of the file that this Editable instance belongs to." />

### <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 a list of all function calls in the code block." />

### <span className="text-primary">if\_blocks</span>

<HorizontalDivider light={true} />

<Attribute type={ <><span>list[</span> <a href="/api-reference/python/PyIfBlockStatement" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PyIfBlockStatement</a> <span>[</span> <a href="/api-reference/python/PyCodeBlock" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PyCodeBlock</a> <span>]]</span></> } description="Returns a list of top level if statements in the code block." />

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

<HorizontalDivider light={true} />

<Attribute type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">int</code> } description="The indentation level of the code block." />

### <span className="text-primary">local\_var\_assignments</span>

<HorizontalDivider light={true} />

<Attribute type={ <><span>list[</span> <a href="/api-reference/python/PyAssignment" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PyAssignment</a> <span>[</span> <a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>,</span> <a href="/api-reference/python/PyCodeBlock" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PyCodeBlock</a> <span>]]</span></> } description="Returns all local variable assignment in the code block, for all nest levels." />

### <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\_block</span>

<HorizontalDivider light={true} />

<Attribute type={ <><a href="/api-reference/python/PyCodeBlock" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PyCodeBlock</a> <span>| None</span></> } description="The parent code block containing this block, or None if it is a top-level block." />

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

<HorizontalDivider light={true} />

<Attribute type={ <><a href="/api-reference/python/PyClass" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PyClass</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/python/PyFunction" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PyFunction</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">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">return\_statements</span>

<HorizontalDivider light={true} />

<Attribute type={ <><span>list[</span> <a href="/api-reference/core/ReturnStatement" style={ {fontWeight: "inherit", fontSize: "inherit"} }>ReturnStatement</a> <span>[</span> <a href="/api-reference/python/PyCodeBlock" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PyCodeBlock</a> <span>]]</span></> } description="Gets all return statements at the top level of the code block." />

### <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">statements</span>

<HorizontalDivider light={true} />

<Attribute type={ <><a href="/api-reference/core/MultiLineCollection" style={ {fontWeight: "inherit", fontSize: "inherit"} }>MultiLineCollection</a> <span>[</span> <a href="/api-reference/core/Statement" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Statement</a> <span>,</span> <a href="/api-reference/python/PyCodeBlock" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PyCodeBlock</a> <span>]</span></> } description="Gets a view of the top-level statements in the code block." />

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

<HorizontalDivider light={true} />

<Attribute type={ <><span>list[</span> <a href="/api-reference/core/SymbolStatement" style={ {fontWeight: "inherit", fontSize: "inherit"} }>SymbolStatement</a> <span>]</span></> } description="Returns list of top level symbol statements in the code block." />

### <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" />

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

<HorizontalDivider light={true} />

<Attribute type={ <><span>list[</span> <a href="/api-reference/python/WithStatement" style={ {fontWeight: "inherit", fontSize: "inherit"} }>WithStatement</a> <span>]</span></> } description="Returns a list of all 'with' statements within the code block." />

## Methods

<HorizontalDivider />

### <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">edit</span>

Replace the source of this `Editable` with `new_src`.

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

<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 text's indentation level. Defaults to False." 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 applied first. 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="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\_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/python/PyCodeBlock" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PyCodeBlock</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/python/PyCodeBlock" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PyCodeBlock</a> <span>]</span></> } description="" />

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

Returns a list of assignments with the specified variable name.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/detached_symbols/code_block.py#L245-L258" />

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

<Return return_type={ <><span>list[</span> <a href="/api-reference/python/PyAssignment" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PyAssignment</a> <span>[</span> <a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>,</span> <a href="/api-reference/python/PyCodeBlock" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PyCodeBlock</a> <span>]]</span></> } description="A list of Assignment objects that match the variable name." />

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

Returns attributes from the code block, with the option to include or exclude private

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/detached_symbols/code_block.py#L186-L201" />

<ParameterWrapper>
  <Parameter name="private" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="Whether to include private attributes in the returned list. If True, returns both private and" defaultValue="" />
</ParameterWrapper>

<Return return_type={ <><span>list[</span> <a href="/api-reference/python/PyAttribute" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PyAttribute</a> <span>[</span> <a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>,</span> <a href="/api-reference/python/PyCodeBlock" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PyCodeBlock</a> <span>]]</span></> } description="A list of attribute statements matching the privacy criteria." />

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

Gets the first comment statement containing a specific text string.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/detached_symbols/code_block.py#L143-L156" />

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

<Return return_type={ <><a href="/api-reference/python/PyComment" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PyComment</a> <span>[</span> <a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>,</span> <a href="/api-reference/python/PyCodeBlock" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PyCodeBlock</a> <span>] | None</span></> } description="The first comment statement containing the search text, or None if no matching comment is found." />

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

Returns the first code statement that assigns a local variable with the specified name.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/detached_symbols/code_block.py#L274-L286" />

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

<Return return_type={ <><a href="/api-reference/python/PyAssignment" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PyAssignment</a> <span>[</span> <a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>,</span> <a href="/api-reference/python/PyCodeBlock" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PyCodeBlock</a> <span>] | None</span></> } description="The first matching local variable assignment, or None if no match is found." />

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

Returns all instances of local variable assignments that match the specified variable

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/detached_symbols/code_block.py#L289-L305" />

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

  <Parameter name="fuzzy_match" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool, optional</code> } description="If True, matches variables whose names contain var_name." defaultValue="False" />
</ParameterWrapper>

<Return return_type={ <><span>list[</span> <a href="/api-reference/python/PyAssignment" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PyAssignment</a> <span>[</span> <a href="/api-reference/core/Editable" style={ {fontWeight: "inherit", fontSize: "inherit"} }>Editable</a> <span>,</span> <a href="/api-reference/python/PyCodeBlock" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PyCodeBlock</a> <span>]]</span></> } description="List of Assignment objects representing local variable assignments that match the specified name criteria." />

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

Returns all statements of a given type up to the specified block level.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/detached_symbols/code_block.py#L103-L115" />

<ParameterWrapper>
  <Parameter name="statement_type" type={ <><a href="/api-reference/core/StatementType" style={ {fontWeight: "inherit", fontSize: "inherit"} }>StatementType</a> <span>| None</span></> } description="The type of statements to return. If None, returns all statement types." defaultValue="None" />

  <Parameter name="max_level" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">int | None</code> } description="The maximum block depth level to search. If None, searches all levels." defaultValue="None" />
</ParameterWrapper>

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

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

Returns all instances of variable usages in a code block.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/detached_symbols/code_block.py#L308-L324" />

<ParameterWrapper>
  <Parameter name="var_name" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The name of the variable 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="When True, matches on variable names that contain var_name. When False (default), only matches exact variable names." 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/python/PyCodeBlock" style={ {fontWeight: "inherit", fontSize: "inherit"} }>PyCodeBlock</a> <span>]]</span></> } description="A sorted list of variable usage instances as Editable objects." />

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

Gets with statements at a specific block level.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/python/detached_symbols/code_block.py#L55-L66" />

<ParameterWrapper>
  <Parameter name="level" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">int</code> } description="The block level to filter by. 0 represents the top level." defaultValue="" />
</ParameterWrapper>

<Return return_type={ <><span>list[</span> <a href="/api-reference/python/WithStatement" style={ {fontWeight: "inherit", fontSize: "inherit"} }>WithStatement</a> <span>]</span></> } description="A list of WithStatement objects at the specified block level." />

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

Adjusts the indentation level of the entire code block.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/detached_symbols/code_block.py#L383-L408" />

<ParameterWrapper>
  <Parameter name="level" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">int</code> } description="The number of indentation levels to adjust. Positive values indent right, negative values indent left." 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">insert\_after</span>

Inserts source code at the bottom of the code block.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/detached_symbols/code_block.py#L363-L380" />

<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." 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 the inserted code. Defaults to True." defaultValue="True" />

  <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 before the inserted code. 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 new source code at the top of the code block.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/detached_symbols/code_block.py#L346-L359" />

<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 at the top of the code block." 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">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>

Deletes this Node and its related extended nodes (e.g. decorators, comments).

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

<ParameterWrapper>
  <Parameter name="delete_formatting" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="Whether to delete surrounding whitespace and formatting. 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="Priority of the removal transaction. Higher priority transactions are executed first. 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 removal transactions at the same location. 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">rename\_variable\_usages</span>

Renames all instances of variable usages in the code block.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/detached_symbols/code_block.py#L327-L342" />

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

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

  <Parameter name="fuzzy_match" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">bool</code> } description="When True, matches variables containing old_var_name. When False, only exact matches. Defaults to False." defaultValue="False" />
</ParameterWrapper>

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">None</code> } description="This method mutates the code block in place." />

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

Search and replace occurrences of text within this node's source and its extended nodes.

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

<ParameterWrapper>
  <Parameter name="old" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The text or pattern to search for." 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 matches with." defaultValue="" />

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

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

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

<Return return_type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">int</code> } description="The total number of replacements made." />

### <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">unwrap</span>

Extracts a code block from its parent wrapper container by removing the wrapping

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/detached_symbols/code_block.py#L436-L475" />

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

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

Wraps a code block with a statement and indents it.

<GithubLinkNote link="https://github.com/codegen-sh/codegen/blob/develop/src/codegen/sdk/core/detached_symbols/code_block.py#L411-L433" />

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

  <Parameter name="after_src" type={ <code className="text-sm bg-gray-100 px-2 py-0.5 rounded">str</code> } description="The source code to insert after the block. Defaults to an empty string." defaultValue="&#x22;&#x22;" />
</ParameterWrapper>

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