Dependency analysis, coupling enforcement, and architectural contract visualization for Django/Python projects.
Project description
grimp-tools
Dependency analysis, coupling enforcement, and architectural contract visualization for Django/Python projects.
Reads configuration from the consumer project's pyproject.toml. Zero config needed if you already use import-linter.
Installation
uv add --dev grimp-tools
Requires Python 3.11+.
Prerequisites
Your project must have import-linter configured with root_packages:
# pyproject.toml
[tool.importlinter]
root_packages = ["api", "game", "engine", "authentication"]
Commands
analyze
Module and app-level dependency analysis with cycle detection.
grimp-tools analyze
grimp-tools analyze --exit-on-cycles # exit 1 if cycles found (CI)
grimp-tools analyze --history docs/deps.log # append timestamped report
grimp-tools analyze --skip migrations,admin # override skip modules
grimp-tools analyze --extra-packages celery # add packages beyond root_packages
snapshot
Save and compare dependency snapshots over time.
grimp-tools snapshot save # save to docs/deps-snapshot.json
grimp-tools snapshot diff # compare current vs saved
grimp-tools snapshot diff --ref master # compare current vs snapshot at git ref
grimp-tools snapshot summary # print metrics without saving
Track docs/deps-snapshot.json in git to see how dependencies evolve across commits.
focus-graph
Focused Mermaid graph showing only what changed between two git refs. Uses worktrees for clean builds.
grimp-tools focus-graph # HEAD vs HEAD~1
grimp-tools focus-graph --new main --old main~1 # specific refs
grimp-tools focus-graph -o docs/focus-graph.md # save .md + .html
contracts-graph
Visualize import-linter contracts as Mermaid diagrams.
grimp-tools contracts-graph # print to stdout
grimp-tools contracts-graph -o docs/contracts.md # save .md + .html
check-names
Validate that Python files follow naming conventions.
grimp-tools check-names # check all tracked .py files
grimp-tools check-names --ref master # only files changed vs ref
Coupling contract (import-linter plugin)
A custom import-linter contract that enforces coupling thresholds as a ratchet: coupling can decrease (warns to update config) but not increase (breaks the contract).
# pyproject.toml
[tool.importlinter]
contract_types = [
"coupling_metrics: grimp_tools.coupling_contract.CouplingMetricsContract",
]
[[tool.importlinter.contracts]]
id = "coupling"
name = "Coupling metrics"
type = "coupling_metrics"
skip_modules = "migrations,admin,apps,management"
top_n = 30
exact_edges = 42
exact_cross_app_edges = 18
Run with lint-imports --verbose to see the full coupling report.
Configuration
All configuration is optional. If [tool.grimp-tools] is absent, defaults are used.
# pyproject.toml
[tool.grimp-tools]
# Modules to skip in analysis (default: migrations, admin, apps, management)
skip_modules = ["migrations", "admin", "apps", "management"]
# Snapshot output path (default: docs/deps-snapshot.json)
snapshot_path = "docs/deps-snapshot.json"
# File naming conventions for check-names
standard_names = [
"models", "managers", "views", "serializers", "services", "urls",
"admin", "apps", "forms", "signals", "tasks", "choices", "fields",
"widgets", "middleware", "decorators", "exceptions", "types",
"perms", "filters", "queries", "factories", "report", "adapters",
"validators", "defaults", "enums", "mixins", "contexts", "caches",
"actions", "tags", "pagination", "storage", "config", "help_texts",
"conftest", "router", "settings", "wsgi", "manage",
]
exempt_dirs = [
"migrations", "management", "commands", "scripts", "docs",
"templatetags",
]
Makefile integration
deps:
grimp-tools analyze --history docs/deps-history.log
snapshot:
grimp-tools snapshot save
focus-graph:
grimp-tools focus-graph --new main --old main~1 -o docs/focus-graph.md
check:
lint-imports
grimp-tools check-names
Releasing
Publishing is automated via GitHub Actions with Trusted Publishers (OIDC, no tokens needed).
To publish a new version:
- Update
versioninpyproject.toml - Commit and push to
main - Create a git tag:
git tag v0.2.0 && git push origin v0.2.0 - Go to GitHub > Releases > "Draft a new release", select the tag, and click "Publish release"
The workflow (.github/workflows/publish.yml) builds and uploads to PyPI automatically via Trusted Publishers.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file grimp_tools-0.2.0.tar.gz.
File metadata
- Download URL: grimp_tools-0.2.0.tar.gz
- Upload date:
- Size: 39.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8bfec10fe1ec2a654519b5f74b5e7ca929fc8a9f1997ecaf6da81dddd5b4cb59
|
|
| MD5 |
357e40c9be6d6a8ca1d11d38a6ec0e4c
|
|
| BLAKE2b-256 |
c5fa6bb6d624044ef62449534d02b747b97b5fd711050f2dadbe2058ca860c2c
|
Provenance
The following attestation bundles were made for grimp_tools-0.2.0.tar.gz:
Publisher:
publish.yml on Virako/grimp-tools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
grimp_tools-0.2.0.tar.gz -
Subject digest:
8bfec10fe1ec2a654519b5f74b5e7ca929fc8a9f1997ecaf6da81dddd5b4cb59 - Sigstore transparency entry: 1338815110
- Sigstore integration time:
-
Permalink:
Virako/grimp-tools@2feab82db919a66ad8d12044c616b7eeef40a529 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Virako
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2feab82db919a66ad8d12044c616b7eeef40a529 -
Trigger Event:
release
-
Statement type:
File details
Details for the file grimp_tools-0.2.0-py3-none-any.whl.
File metadata
- Download URL: grimp_tools-0.2.0-py3-none-any.whl
- Upload date:
- Size: 36.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5597a322f02fce0a0ed9195abb0c09b4c23c6189a19bf2e91e247fa1cb86abf8
|
|
| MD5 |
2070547f246b51f09226720dc23b2278
|
|
| BLAKE2b-256 |
6b34f58dd296f8e0ca9e1010793c81632876976e7cc84328fc6d969c3109ca1b
|
Provenance
The following attestation bundles were made for grimp_tools-0.2.0-py3-none-any.whl:
Publisher:
publish.yml on Virako/grimp-tools
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
grimp_tools-0.2.0-py3-none-any.whl -
Subject digest:
5597a322f02fce0a0ed9195abb0c09b4c23c6189a19bf2e91e247fa1cb86abf8 - Sigstore transparency entry: 1338815111
- Sigstore integration time:
-
Permalink:
Virako/grimp-tools@2feab82db919a66ad8d12044c616b7eeef40a529 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/Virako
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@2feab82db919a66ad8d12044c616b7eeef40a529 -
Trigger Event:
release
-
Statement type: