Skip to main content

Python repo graph builder with AST parsing, SCC, centrality, graph diffing, dead-code candidates, JSON, and Mermaid export.

Project description

repo-graph-kit

A small Python-first repo graph package.

It parses Python repositories with ast, builds a directed graph of modules, imports, classes, functions, methods, and calls, then exports the result as JSON or Mermaid.

Features

  • Python AST repo graph builder
  • Modules, imports, classes, functions, methods, inheritance, and calls
  • Better local symbol and import alias call resolution
  • DFS traversal
  • BFS shortest path
  • Strongly Connected Components using Tarjan's algorithm
  • Topological sort for dependency ordering
  • Degree centrality for blast-radius and hotspot detection
  • Graph diffing for CI and PR tracking
  • Dead-code candidate detection
  • JSON export
  • Mermaid export
  • CLI command: repo-graph

Install locally

pip install -e .

Publish to PyPI

This project is ready for standard PyPI packaging:

  • build backend: setuptools
  • package layout: src/
  • CLI entry point: repo-graph

To release a version:

  1. Update version in pyproject.toml.
  2. Install release tools with python -m pip install --upgrade build twine.
  3. Build distributions with python -m build.
  4. Verify them with python -m twine check dist/*.
  5. Upload to TestPyPI first, then to PyPI.

For automated releases, configure PyPI Trusted Publishing and use the GitHub Actions workflow in .github/workflows/publish.yml.

Build a graph

repo-graph scan ./examples/sample_project \
  --json out/repo-graph.json \
  --mermaid out/repo-graph.mmd \
  --findings out/findings.json \
  --metrics out/metrics.json

Diff two graphs

repo-graph diff previous/repo-graph.json current/repo-graph.json \
  --json out/graph-diff.json

Python API

from repo_graph_kit import build_python_repo_graph
from repo_graph_kit.algorithms import (
    strongly_connected_components,
    top_central_nodes,
    diff_graphs,
)

graph = build_python_repo_graph("examples/sample_project")

print(len(graph.nodes))
print(len(graph.edges))

print(strongly_connected_components(graph, edge_types={"imports"}))
print(top_central_nodes(graph, limit=5, edge_types={"imports", "calls"}))

Current limitations

This is intentionally static-analysis-first. It will not perfectly resolve dynamic imports, monkey patching, dependency injection, framework magic, or runtime-generated calls.

Treat findings like dead-code candidates as review hints, not automatic deletion instructions.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

repo_graph_kit-0.2.0.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

repo_graph_kit-0.2.0-py3-none-any.whl (16.3 kB view details)

Uploaded Python 3

File details

Details for the file repo_graph_kit-0.2.0.tar.gz.

File metadata

  • Download URL: repo_graph_kit-0.2.0.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for repo_graph_kit-0.2.0.tar.gz
Algorithm Hash digest
SHA256 2973b63162888af037a4a640384009315195edfdbd4e572899578000e22a584b
MD5 58de6ef533d57787ef718feb7a4b418d
BLAKE2b-256 fe6eb0ee274e018c9c58e4474ab20a487ffa73acfdde6692f3dd3d3a906b63b8

See more details on using hashes here.

File details

Details for the file repo_graph_kit-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: repo_graph_kit-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 16.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for repo_graph_kit-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d4c503fb7ba98be650aef643ecb2f8504ccf4e06acfea23195568b48ad30af58
MD5 a9e7c85b59219cc0182bf7ac2f1a39df
BLAKE2b-256 04e97f13baffddaa1f0af876d0877de1313b38dfcbac7cf026412dcf40b58522

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page