Skip to content

[Python] Add code-graph extractor #94

Description

@theDakshJaitly

Target branch: code-graph-preview

Goal

Add the first community language extractor by implementing Python support against the frozen LanguageExtractor interface. The first version should provide a reliable structural graph for common Python modules without attempting framework-specific behavior.

Scope

  • Detect .py files as python.
  • Vendor and register a compatible Tree-sitter Python WASM grammar.
  • Emit a file node and containment tree.
  • Extract functions, async functions, classes, methods, module variables, and constants where they can be identified reliably.
  • Capture signatures, documentation strings, export visibility conventions, and return annotations when present.
  • Emit imports, calls, containment, inheritance, and instantiation references.
  • Leave cross-file targets unresolved through targetName for the existing resolution pass.

Required changes

  • Add src/graph/extraction/languages/python.ts.
  • Register the extractor in src/graph/extraction/languages/index.ts.
  • Register .py and the grammar filename in src/graph/extraction/grammars.ts.
  • Add the grammar WASM under src/graph/wasm/ and document its source, version, and license.
  • Add a representative Python fixture under src/graph/__tests__/fixtures/.
  • Add focused extractor tests under src/graph/__tests__/.

Acceptance criteria

  • The extractor implements the frozen LanguageExtractor interface without changing it.
  • Extraction is pure, deterministic, and limited to one file.
  • Node ids use generateNodeId(filePath, kind, name).
  • Tests cover file identity, functions, classes, methods, qualified names, containment, imports, calls, inheritance, and instantiation.
  • Cross-file references remain unresolved for the engine to bind.
  • Unsupported or malformed syntax degrades without crashing graph construction.
  • npm run typecheck, npm test, and npm run build pass.
  • The packed build contains the Python grammar WASM.

Out of scope

  • Django, Flask, FastAPI, or other framework semantics.
  • Runtime import execution or Python environment inspection.
  • Type inference beyond explicit syntax.
  • Changes to identity, reconciliation, schema, or grounding semantics.

Contributor references

Contributor workflow

git switch code-graph-preview
git pull
git switch -c feat/python-code-graph-extractor

Open the pull request with base branch code-graph-preview.

Metadata

Metadata

Assignees

No one assigned

    Labels

    code-graphWork related to the AST and Tree-sitter code graphdeveloper-previewPart of an unreleased developer previewgood first issueGood for newcomerslanguage-supportAdds or improves support for a programming languagetree-sitterTree-sitter grammars, parsing, or extraction

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions