Static analysis + MCP server for Django and SQLAlchemy models. ER diagrams, N+1, migration risk for Django migrations and Alembic, blast radius and schema drift for CI, terminals and AI agents. No DB, no app boot. Free and MIT.
pip install orm-lens==1.17.1 Copy PIP instructions
Formerly django-orm-lens: pip install django-orm-lens still works, installs this package and keeps the old django-orm-lens command and import django_orm_lens.
SQLAlchemy (preview): scan, er and nplusone read SQLAlchemy 2.0 / 1.x, Flask-SQLAlchemy and SQLModel models, and migration-risk reads Alembic revisions — see SQLAlchemy models and Alembic rules.
Listed in the official MCP Registry as io.github.FROWNINGdev/orm-lens.
Ships with a zero-dependency parser, a JSON/Markdown/table CLI, and an optional MCP (Model Context Protocol) server so any AI coding agent — Cursor, Aider, Continue, and any other MCP client — can navigate your Django schema without importing Django or spinning up your app.
Schema review is a paid category nearly everywhere. A bot that reviews every pull request, analysis that follows a queryset past the function it was built in, a check that catches schema drift, index advice grounded in real table statistics — those normally sit behind a per-seat or per-database subscription.
All of it is here, MIT-licensed, with no tier gate, no seat count, no account and no telemetry:
# Core CLI (zero third-party deps) pip install orm-lens # With the MCP server (adds the `mcp` package) pip install "orm-lens[mcp]" Requires Python 3.9+; the MCP server needs 3.10+, like the mcp SDK. Works on Linux, macOS, and Windows.
# Scan a Django project for models (JSON, Markdown, or table) orm-lens scan -f json orm-lens scan -f markdown orm-lens scan -f table # Describe one model orm-lens describe blog.Post orm-lens describe Post -f json # Compact hover card (great for pipeing into your editor) orm-lens hover blog.Post # Flat list — pipes into fzf, grep, etc. orm-lens list | fzf # ER diagram — Mermaid (default), DBML, D2, or PlantUML orm-lens er > schema.mmd orm-lens er -f dbml > schema.dbml # paste into dbdiagram.io orm-lens er -f d2 > schema.d2 # render: d2 schema.d2 schema.svg orm-lens er -f plantuml > schema.puml # Diff two schema dumps (exit 1 on changes — CI-friendly) orm-lens diff before.json after.json # Static analyzers — text, json, sarif, or github annotation output orm-lens nplusone --format github # N+1 findings as PR annotations orm-lens migration-risk -f sarif # SARIF for GitHub Code Scanning orm-lens suggest-indexes blog.Post # Meta.indexes proposals from usage orm-lens signals # sender→signal→handler graph orm-lens migration-deps blog -f mermaid # per-app migration DAG orm-lens cascade blog.Author # delete blast radius by on_delete Every command accepts --path and repeatable --exclude . Defaults skip migrations/, venv/, .venv/, env/, and node_modules/.
The MCP server exposes ten read-only tools that any MCP-compatible agent can call while it edits your Django project:
orm-lens-mcp # dedicated entry point # or orm-lens mcp # subcommand Workspace resolution (py-1.3.0+). Priority: explicit workspace_root argument on the tool call → ORM_LENS_ROOT env var → current working directory. If none resolves to a Django project (manage.py, django in pyproject.toml, or any models.py) you get a structured error envelope back — {"error": "WORKSPACE_NOT_DJANGO", "hint": "…"} — instead of an empty list, so the agent knows what to do next.
Optional sandbox: set ORM_LENS_ALLOWED_ROOTS (;-separated on Windows, :-separated elsewhere) to a whitelist of prefixes; any path outside them is rejected with WORKSPACE_NOT_ALLOWED.
{ "mcpServers": { "orm-lens": { "command": "orm-lens-mcp", "env": { "ORM_LENS_ROOT": "/abs/path/to/your/project" } } } } Any MCP client — same shape, generic tool. Point command at the installed orm-lens-mcp binary. Two ways to tell it which Django project to scan:
The tool signatures include workspace_root: str = "" as an optional parameter, so any agent inspecting tools/list sees it and can supply it.
diff and nplusone exit 1 on findings; migration-risk exits 1 on critical findings (--exit-zero for report-only). Two annotation-ready formats: --format github prints ::warning/::error workflow commands (PR annotations with no extra permissions), --format sarif emits SARIF 2.1.0 for github/codeql-action/upload-sarif.
repos: - repo: https://github.com/FROWNINGdev/orm-lens rev: py-v1.17.1 hooks: - id: orm-lens-nplusone - id: orm-lens-migration-risk GitHub Actions users get a composite action: uses: FROWNINGdev/orm-lens@action-v1 with command: / format: inputs.
Django's ORM is Python, and Python is dynamic. AI agents that only see models.py as raw text miss:
orm-lens gives them a static, deterministic, JSON view of the schema — no Django boot, no database, no side effects. And you get a nice CLI for humans too.
from orm_lens import scan_workspace index = scan_workspace(".") for app in index.apps: for model in app.models: print(f"{app.name}.{model.name} — {len(model.fields)} fields") # The full parsed tree serialises to the same JSON schema the VS Code # extension emits, so tools can share it interchangeably. import json json.dumps(index.to_dict(), indent=2) Links Repo: https://github.com/FROWNINGdev/orm-lens Issues: https://github.com/FROWNINGdev/orm-lens/issues Changelog: https://github.com/FROWNINGdev/orm-lens/blob/main/CHANGELOG.md VS Code extension: https://marketplace.visualstudio.com/items?itemName=frowningdev.django-orm-lens MIT licensed.
django sqlalchemy alembic fastapi flask sqlmodel orm n+1 migrations models er-diagram mermaid mcp ai-agents cursor aider code-analysis static-analysis
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
None of the files in this release were uploaded with provenance metadata.
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.




