Use case: what connects to what

In a large Python codebase, a change to one module can break modules you have never opened, and one new import can cause a circular-import error at run time. tangle stores module → imports → module (with the line, and whether the import runs at import time, lazily or only for type checking) and module → uses → outside package in Relate, and answers:

  • impact M: everything that depends on M, directly or indirectly
  • why A B: the shortest import chain from A to B, with file and line per step (Cypher shortestPath)
  • cycles: groups of modules that import each other in a loop, with one example loop each
  • top and query: aggregations and any Cypher you write

How it uses Relate

  • Mode: single file. The graph is a build artefact of one codebase: one file written by tangle scan, committed or attached to CI, opened read-only by every later command, and inspectable by anyone with Relate, with no server.
  • Graph: (:Module {name, path, loc, is_package}), (:External {name}), (:Module)-[:IMPORTS {kind, line, count}]->(:Module|:External), (:Scan {...}), created with UNWIND batches.
  • What I learned with Relate: unbounded variable-length patterns ([:IMPORTS*] for impact, (a)-[*1..6]->(a) for cycles) explode on scikit-learn's 1,774 edges, so impact became a breadth-first walk of one-hop Cypher queries and cycles became strongly connected components over edges read with Cypher. shortestPath works directly.

Results (real, python scripts/build_examples.py)

  • scikit-learn 1.9.1 (tests excluded): 351 modules, 1,774 internal imports, scanned and stored in 1.26 s; 676 KB store. 17 import-time loop groups (90 modules), and every one goes through a submodule importing its own package (sklearn/base.py line 17 from sklearn import __version__, while sklearn/__init__.py line 70 imports sklearn.base). With --ignore-parents, none remain. A change to sklearn.utils.validation can reach 237 of 351 modules.
  • requests 2.34.2: 19 modules, 80 internal imports, no import-time loops; one 8-module loop exists only through type-checking imports.
  • 10 pytest tests on a fixture project; impact is cross-checked against a plain Python search.

Setup (judges can run without asking)

git clone https://github.com/PrafullJ0shi/tangle && cd tangle
python -m venv .venv && .venv\Scripts\Activate.ps1   (or source .venv/bin/activate)
pip install -e ".[dev]"
tangle cycles --db examples/sklearn.rl
tangle why requests.api requests.compat --db examples/requests.rl

Limitations

Static analysis only: importlib.import_module(name) is not seen. Compiled extension modules are not nodes. from x import * points at x only.

AI assistance

Built with AI-assisted coding: an AI coding assistant helped write the code, tests and documentation. The README states this. New project; all code written on 1 Dec 2026.

Built With

Share this project:

Updates

Submission history