Static analysis + MCP server for Django models. Sidebar tree, ER diagrams, and JSON output for terminals and AI coding agents.
Project description
django-orm-lens
Static analysis + MCP server for Django models. Terminal- and AI-agent-friendly.
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.
Companion to the Django ORM Lens VS Code extension.
Install
# Core CLI (zero third-party deps)
pip install django-orm-lens
# With the MCP server (adds the `mcp` package)
pip install "django-orm-lens[mcp]"
Requires Python 3.9+. Works on Linux, macOS, and Windows.
CLI usage
# Scan a Django project for models (JSON, Markdown, or table)
django-orm-lens scan -f json
django-orm-lens scan -f markdown
django-orm-lens scan -f table
# Describe one model
django-orm-lens describe blog.Post
django-orm-lens describe Post -f json
# Compact hover card (great for pipeing into your editor)
django-orm-lens hover blog.Post
# Flat list — pipes into fzf, grep, etc.
django-orm-lens list | fzf
# Emit a Mermaid ER diagram
django-orm-lens er > schema.mmd
django-orm-lens er -o schema.mmd
Every command accepts --path <dir> and repeatable --exclude <glob>. Defaults
skip migrations/, venv/, .venv/, env/, and node_modules/.
MCP server — for AI coding agents
The MCP server exposes five read-only tools that any MCP-compatible agent can call while it edits your Django project:
| Tool | Purpose |
|---|---|
list_apps |
Every Django app in the workspace with model counts |
list_models |
Flat app.Model list, optional app filter |
describe_model |
Full field / relation / Meta detail for one model |
find_relations |
Inbound + outbound relations for one model |
er_diagram |
Mermaid erDiagram string for the whole workspace |
Start the server manually
django-orm-lens-mcp # dedicated entry point
# or
django-orm-lens mcp # subcommand
By default the server scans the current working directory. Override with
DJANGO_ORM_LENS_ROOT=/abs/path/to/project.
Register it with an agent
Cursor — add to ~/.cursor/mcp.json:
{
"mcpServers": {
"django-orm-lens": {
"command": "django-orm-lens-mcp",
"env": { "DJANGO_ORM_LENS_ROOT": "/abs/path/to/your/project" }
}
}
}
Aider / Continue.dev / Zed / any MCP client — same shape, the tool is
generic. Point command at the installed django-orm-lens-mcp binary and set
the workspace root via env.
Why?
Django's ORM is Python, and Python is dynamic. AI agents that only see
models.py as raw text miss:
- which fields belong to which model;
- the direction and cardinality of every relation;
- what
Meta.ordering,unique_together, andconstraintsactually contain; - which app owns which model when the project uses split
models/packages.
django-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.
Programmatic API
from django_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/django-orm-lens
- Issues: https://github.com/FROWNINGdev/django-orm-lens/issues
- Changelog: https://github.com/FROWNINGdev/django-orm-lens/blob/main/CHANGELOG.md
- VS Code extension: https://marketplace.visualstudio.com/items?itemName=frowningdev.django-orm-lens
MIT licensed.
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
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 django_orm_lens-1.0.1.tar.gz.
File metadata
- Download URL: django_orm_lens-1.0.1.tar.gz
- Upload date:
- Size: 15.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eadf90ac37b8dedac434244a53bf29826ad73bf93a37c5f4a393755b3acdb07e
|
|
| MD5 |
c780d8b46d17cd587879aa954ba81235
|
|
| BLAKE2b-256 |
6c285e5ead526027f5eb63a5fa519cc629c8bd78090228838853c273a48e0856
|
File details
Details for the file django_orm_lens-1.0.1-py3-none-any.whl.
File metadata
- Download URL: django_orm_lens-1.0.1-py3-none-any.whl
- Upload date:
- Size: 15.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.10
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8b84d0889fcd05c283289da6aae0cebaab8eb16fe5c6b080e2b3b6998f9ff532
|
|
| MD5 |
0fb33c4e59d07debe897159ef02a0281
|
|
| BLAKE2b-256 |
ca34d96bcef5426572304f94c1f30ac603680a841b14eabd30ebc26dcae98203
|