Docs / languages / python · Edit on GitHub

Python

Tier 1 plugin for Python 3 source. Extracts modules, classes, functions, imports, inheritance, decorators, instantiation, and call edges.

Implementation

Plugin cratecrates/rgctl-lang-python (PythonPlugin)
Grammartree-sitter-python
Extensions.py, .pyw
Discoverrgctl discover . -l python -e .venv,__pycache__ --with-cfg
CFG / taintEnabled (LanguageAnalysisProfile)

Tree-sitter node kinds (from languages.toml): function_definition, class_definition, import_statement, import_from_statement.

What is extracted

Nodes

  • Function — module-level and class methods; qualified_name for class methods (e.g. OrderService.checkout)
  • Class — classes with inheritance
  • Importimport and from … import module graph
  • Module — file-level module nodes

Edges

EdgeMeaning
CALLSResolved function/method calls
EXTENDSClass inheritance (class Foo(Bar))
ANNOTATEDWITHDecorators on functions and classes
INSTANTIATESnew / constructor calls (Foo())
ImportModule import relations

Verification

Fixturergctl-tests/ecommerce-python
Example corpusexample/home-assistant (-l python)
Smoke scriptrgctl-tests/gql-verification-smoke/verify-extraction-gql-python.sh
RGCTL=target/release/rgctl ./rgctl-tests/gql-verification-smoke/verify-extraction-gql-python.sh

GQL verification queries

Run after discover on the fixture. Replace <repo> with the fixture path.

Fixture probes

ProbeGQL
Module graph (Import)MATCH (n:Import) RETURN n LIMIT 10000
Heritage (EXTENDS)MATCH (a)-[:EXTENDS]->(b) RETURN a,b LIMIT 10000
Decorators (ANNOTATEDWITH)MATCH (a)-[:ANNOTATEDWITH]->(b) RETURN a,b LIMIT 10000
Instantiation (INSTANTIATES)MATCH (a)-[:INSTANTIATES]->(b) RETURN a,b LIMIT 10000
Call resolution (CALLS)MATCH (a)-[:CALLS]->(b) RETURN a,b LIMIT 10000
Method FQN (OrderService.*)MATCH (n:Function) WHERE n.qualified_name LIKE 'OrderService.*' RETURN n LIMIT 20

Example smoke (example/home-assistant)

ProbeGQL
Import (scale)MATCH (n:Import) RETURN n LIMIT 10000
EXTENDS (scale)MATCH (a)-[:EXTENDS]->(b) RETURN a,b LIMIT 10000
ANNOTATEDWITH (scale)MATCH (a)-[:ANNOTATEDWITH]->(b) RETURN a,b LIMIT 10000
INSTANTIATES (scale)MATCH (a)-[:INSTANTIATES]->(b) RETURN a,b LIMIT 10000
CALLS (scale)MATCH (a)-[:CALLS]->(b) RETURN a,b LIMIT 10000

Related

  • Languages index
  • Openspec: python-module-graph, python-heritage, python-decorators, python-call-resolution