Python language plugin for CodeGraph. Extracts code entities from Python source files using tree-sitter-python.
.py, .pyw, .pyi
- Functions --
defandasync defdeclarations with:- Type annotations (parameters and return types)
- Docstrings (triple-quoted strings as first body statement)
- Async detection
- Method detection (inside class bodies)
- Complexity metrics (cyclomatic, cognitive, nesting depth)
self/clsparameters filtered out automatically
- Classes --
classdeclarations with:- Superclass extraction from argument list
- Docstrings
- Method enumeration
- Export detection via
_prefix convention
- Variables -- Top-level assignments with:
- Constant detection (
UPPER_CASEnaming) - Basic type inference from right-hand side
- Constant detection (
- Imports --
importandfrom ... importstatements with:- Named specifiers and aliases (
import X as Y) - Namespace vs named import distinction
- Python import path resolution (relative and absolute)
- Named specifiers and aliases (
- CALLS -- Function-to-function call references (filters Python builtins:
print,len,range,isinstance, etc.) - Inheritance -- Derived from class
extendsfields
Uses the @codegraph/plugin-generic factory with custom override extractors for Python-specific behavior (docstrings, type annotations, parameter filtering, import resolution). The plugin is exported as pythonPlugin.
import { pythonPlugin } from '@codegraph/plugin-python';
pythonPlugin.extractAllEntities(root, filePath);
// Individual extractors
import {
extractFunctions,
extractClasses,
extractVariables,
extractImports,
extractCalls,
extractInheritance,
resolvePythonImport,
} from '@codegraph/plugin-python';Uses tree-sitter-python.