Skip to main content

Code Knowledge Graph: static analysis + LLM-assisted refactoring pipeline

Project description

pyrere (Python Repo Review)

PyPI version Python 3.10+ License: MIT CI

Code Knowledge Graph — static analysis + LLM-assisted refactoring pipeline for Python repositories.

pyrere parses a Python repository with tree-sitter, builds a typed graph of modules, classes and functions, optionally enriches it with pyright / grimp / pycg, annotates it with static-analysis issues (ruff, vulture, bandit), and opens an interactive in-browser viewer.


Installation

pip install pyrere

With optional enrichment / flow tools:

pip install "pyrere[all]"          # everything
pip install "pyrere[flow]"         # ruff + vulture + bandit
pip install "pyrere[enrichment]"   # pyright + grimp + pycg

Note — pyright requires Node.js: pyright is a Node.js program installed via a thin pip shim. pip install pyrere[enrichment] will succeed on machines without Node.js, but running the enrichment step will fail at runtime. Install Node.js 18+ from https://nodejs.org before using the enrichment extra. pyrere degrades gracefully when pyright is absent — the enrichment step is simply skipped with a printed warning.

Note — pycg compatibility: pycg (a points-to call-graph tool included in the enrichment extra) is a research project with limited maintenance and known install issues on Python 3.11+. pyrere handles a missing or broken pycg gracefully — the call-graph enrichment step is skipped automatically. If you hit install errors with pip install "pyrere[enrichment]" try omitting pycg:

pip install "pyrere[flow]" pyright grimp

Quick start

# Analyse the current directory and open the viewer
pyrere .

# Analyse a specific repo
pyrere /path/to/your/repo

# Use a custom port (default: 8000)
pyrere /path/to/your/repo --port 8080

The viewer will open at http://localhost:8000.


Python API

from pyrere import build_graph, enrich_graph, annotate_graph

graph = build_graph("/path/to/repo")
enrich_graph(graph, "/path/to/repo")   # optional: pyright/grimp/pycg
annotate_graph(graph, "/path/to/repo") # optional: ruff/vulture/bandit

print(f"{len(graph.nodes)} nodes, {len(graph.edges)} edges")

tree-sitter version note

The default install uses the legacy bundle (tree-sitter < 0.22, tree-sitter-languages) which ships pre-compiled grammars for ~100 languages and requires no compiler.

Pre-built wheels for tree-sitter-languages are available for the most common platforms (CPython 3.10-3.12 on Linux x86_64/arm64, macOS, Windows x64). On other platforms (e.g. Alpine Linux, RISC-V, PyPy) pip will attempt to build from source and will need a C compiler (gcc / clang) plus the Python headers (python3-dev / python3-devel).

To use the modern per-language packages instead (no compiler required on all platforms that have a tree-sitter-python wheel), install manually:

pip install "tree-sitter>=0.22" tree-sitter-python

and update dependencies in your local pyproject.toml accordingly.


Viewer and internet access

The interactive graph viewer loads vis-network from the unpkg CDN at a pinned version. An active internet connection is required the first time the viewer is opened in each browser session.

For offline use, download the JS file once and place it alongside the viewer:

curl -Lo "$(python -c "import pyrere, os; print(os.path.join(os.path.dirname(pyrere.__file__), '_viewer', 'vis-network.min.js'))")" \
  https://unpkg.com/vis-network@9.1.9/standalone/umd/vis-network.min.js

Then edit _viewer/index.html to change the <script src="..."> line to <script src="vis-network.min.js">.


Development

git clone https://github.com/3ivis/pyrere
cd pyrere
pip install -e ".[dev]"
pytest

License

MIT

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

pyrere-0.1.0.tar.gz (40.7 kB view details)

Uploaded Source

Built Distribution

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

pyrere-0.1.0-py3-none-any.whl (43.0 kB view details)

Uploaded Python 3

File details

Details for the file pyrere-0.1.0.tar.gz.

File metadata

  • Download URL: pyrere-0.1.0.tar.gz
  • Upload date:
  • Size: 40.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for pyrere-0.1.0.tar.gz
Algorithm Hash digest
SHA256 018a1e17ca4a9a9a93171fccb9eb7b3bed3a6ce12efe95166fa994a1f86ccbee
MD5 6233d68a5554bb1d36b364f18f101ca7
BLAKE2b-256 c794730d74e9176cca1feb8796e549e08bf65e8f4f78aa798d03b1062c469664

See more details on using hashes here.

File details

Details for the file pyrere-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyrere-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 43.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for pyrere-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2cd6d94c42bc26eb33e4355323f638d94cf22c7974a1aea6626a7c53a0acd493
MD5 611045a762400db2b45d45fc0c621a1e
BLAKE2b-256 8b80bb526c50398844c49be629e2e81e22cf30b93d320a5b30eefbb0b04f0807

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