Python Code Analysis

Full-depth analysis of Python applications, ML pipelines, Django/Flask/FastAPI services, and data processing systems

What Axiom Refract Analyzes in Python

Import Graph Extraction

Resolves both absolute and relative Python imports, including conditional imports, lazy imports inside functions, and dynamic importlib usage. Maps the complete import graph across packages, modules, and __init__.py re-exports.

Class Hierarchy and Method Resolution

Extracts full class inheritance hierarchies including multiple inheritance and mixin patterns. Resolves method resolution order (MRO) and identifies overridden methods, abstract method implementations, and protocol conformance.

Decorator and Metaclass Detection

Identifies decorator usage patterns including route decorators (Flask/FastAPI), ORM model decorators (SQLAlchemy/Django), and custom decorators. Detects metaclass-driven patterns that affect class structure.

Type Annotation Parsing

Parses Python type annotations including generics, Union types, Optional, TypeVar, Protocol definitions, and TypedDict structures to enhance dependency resolution accuracy.

Framework-Specific Patterns

Recognizes Django models, views, URLs, and middleware chains. Identifies FastAPI route dependencies, SQLAlchemy model relationships, Celery task definitions, and pytest fixture dependency graphs.

Async/Await Flow Analysis

Traces async call chains through coroutines, async generators, and async context managers. Identifies synchronous calls within async contexts that could create blocking bottlenecks.

How It Works

Python is parsed using a hand-hardened Tree-sitter grammar that handles Python 3.6 through 3.13 syntax, including walrus operators, match/case statements, exception groups, and type parameter syntax (PEP 695). The parser correctly handles Python's significant whitespace by maintaining indentation context throughout the parse tree, ensuring accurate scope resolution even in deeply nested code. Dynamic import patterns using importlib are detected heuristically and flagged with lower confidence scores.

Common Findings in Python Codebases

Circular Import Dependencies

Python's module-level import execution makes circular imports particularly dangerous. Axiom detects circular import chains that may cause ImportError at runtime depending on import order.

God Module Anti-Pattern

Python projects frequently develop oversized __init__.py files or utility modules that become single points of failure with high centrality scores. Axiom identifies these modules and calculates their blast radius.

Dead Import Accumulation

Python files commonly accumulate unused imports that create false dependency relationships. Axiom identifies imports that are declared but never referenced in the module scope.

Tight Coupling Through Global State

Python's module-level global variables and singleton patterns create implicit coupling between modules. Axiom detects shared mutable state patterns that increase structural fragility.

Polyglot Support

Python is one of 145+ languages Axiom Refract supports through Tree-sitter AST parsing. Python analysis covers PyPI packages, requirements.txt, setup.py, setup.cfg, pyproject.toml (PEP 621), Pipfile, and conda environment files. Virtual environment structures are detected and excluded from analysis to prevent false dependency mappings. Your entire codebase is analyzed in a single scan — regardless of how many languages it contains.

Analyze your Python codebase.