A Django app to generate Documentation for Django Project Template.
Project description
magnet-dpt-doc-generator
Django management commands that use the Claude API (Anthropic) to automatically generate technical documentation for your project.
Installation
pip install magnet-dpt-doc-generator
Add the app to your INSTALLED_APPS:
INSTALLED_APPS = [
...
"magnet_dpt_doc_generator",
]
Requirements
An Anthropic API key is required. Set it in your settings.py or as an environment variable:
# settings.py
ANTHROPIC_API_KEY = "sk-ant-..."
export ANTHROPIC_API_KEY="sk-ant-..."
Commands
generate_docs — Generate SRS documentation
Scans your Django apps and generates a Markdown SRS (Software Requirements Specification) document per Python file using Claude. Output defaults to docs/SRS/.
# Document the whole project
python manage.py generate_docs
# Document specific apps only
python manage.py generate_docs --apps orders inventory
# Document a single file
python manage.py generate_docs --only orders/views.py
# Use extra directories as context (read by Claude, not documented)
python manage.py generate_docs --apps orders --context-dirs users core
# Custom output directory
python manage.py generate_docs --output ./my-docs
# Preview files that would be documented without calling the API
python manage.py generate_docs --dry-run
# Regenerate files that already exist
python manage.py generate_docs --force
# Reduce delay between API calls (default: 15s, use 0 for higher-tier plans)
python manage.py generate_docs --delay 2
Options:
| Option | Default | Description |
|---|---|---|
--output DIR |
docs/SRS |
Output directory for .md files |
--apps APP [APP ...] |
(whole project) | Django apps to document |
--context-dirs DIR [DIR ...] |
— | Dirs Claude reads as context without documenting |
--only FILE |
— | Document a single file (relative to project root) |
--glossary FILE |
docs/GLOSSARY.md |
Path to glossary file |
--dry-run |
False |
List files without calling the API |
--force |
False |
Overwrite existing .md files |
--delay SECONDS |
15 |
Pause between API calls |
generate_glossary — Generate a domain glossary
Scans your apps in three phases — term extraction, definition from code evidence, and inference — to produce a GLOSSARY.md table of domain terms and acronyms.
# Generate glossary from scratch
python manage.py generate_glossary --apps orders inventory
# Add new terms without overwriting existing ones
python manage.py generate_glossary --apps orders inventory --update
# Custom output path
python manage.py generate_glossary --apps orders --output docs/MY_GLOSSARY.md
Options:
| Option | Default | Description |
|---|---|---|
--apps APP [APP ...] |
(required) | Django apps to scan |
--output FILE |
docs/GLOSSARY.md |
Glossary output file |
--update |
False |
Add new terms, preserve existing entries |
--delay SECONDS |
15 |
Pause between API calls |
How it works (3 phases):
- Phase 1 — Collect: Scans
.pyand.pofiles to extract candidate domain terms. - Phase 2 — Define: Searches the same files for explicit definitions in code.
- Phase 3 — Infer: Uses Claude to infer definitions for remaining undefined terms.
generate_brd — Generate BRD documentation
Reads the SRS docs generated by generate_docs and produces BRD (Business Requirements Document) files organized by business flow. Output defaults to docs/BRD/.
Run generate_docs first — this command requires the SRS output as input.
# Discover business flows from the SRS
python manage.py generate_brd --discover
# Document a specific flow
python manage.py generate_brd --flow "Carga de Subestaciones"
# Document a flow inside a subdirectory
python manage.py generate_brd --flow "Carga de Subestaciones" --subdir "Extracción"
# Overwrite an existing flow file
python manage.py generate_brd --flow "Carga de Subestaciones" --force
# Regenerate README indexes only (no new flow files)
python manage.py generate_brd --reindex
python manage.py generate_brd --reindex --subdir "Extracción"
Options:
| Option | Default | Description |
|---|---|---|
--discover |
— | Analyze SRS and propose a list of business flows |
--flow NAME |
— | Name of the business flow to document |
--reindex |
— | Regenerate README index files without creating new flows |
--subdir NAME |
— | Subdirectory inside the BRD output dir |
--output DIR |
docs/BRD |
BRD root output directory |
--srs-dir DIR |
docs/SRS |
SRS input directory |
--glossary FILE |
docs/GLOSSARY.md |
Path to glossary file |
--root-urls FILE |
project/urls.py |
Root urls.py relative to BASE_DIR |
--srs-files FILE [FILE ...] |
— | Extra .md files appended to the SRS context |
--description TEXT |
— | Optional one-line description of the flow |
--force |
False |
Overwrite an existing flow file |
--delay SECONDS |
15 |
Pause between API calls |
Recommended workflow
# 1. Generate the glossary first (optional but improves doc quality)
python manage.py generate_glossary --apps myapp
# 2. Generate SRS documentation
python manage.py generate_docs --apps myapp
# 3. Discover business flows
python manage.py generate_brd --discover
# 4. Document each flow
python manage.py generate_brd --flow "My Flow Name"
Configuration
All defaults can be overridden in your project's settings.py using the MAGNET_DPT_ prefix:
# settings.py
# Output paths (relative to BASE_DIR)
MAGNET_DPT_DOCS_OUTPUT_DIR = "docs/SRS"
MAGNET_DPT_GLOSSARY_PATH = "docs/GLOSSARY.md"
MAGNET_DPT_BRD_OUTPUT_DIR = "docs/BRD"
# Claude model settings
MAGNET_DPT_MODEL = "claude-sonnet-4-20250514"
MAGNET_DPT_MAX_TOKENS = 4096
MAGNET_DPT_MAX_CONTEXT_CHARS = 40_000
# Rate limiting (seconds between API calls)
# Free tier: ~15-20s | Build tier: ~2-3s | Higher tiers: 0
MAGNET_DPT_REQUEST_DELAY_SECONDS = 15
MAGNET_DPT_MAX_RETRIES = 3
MAGNET_DPT_RETRY_BACKOFF = 60 # multiplied by attempt number
# Scanning filters (provide as lists)
MAGNET_DPT_IGNORE_DIRS = ["__pycache__", ".git", ".venv", "venv", "node_modules", "migrations", "tests"]
MAGNET_DPT_IGNORE_PATHS = ["manage.py", "wsgi.py", "asgi.py", "settings.py", "admin.py",
"apps.py", "tests.py", "urls.py", "fixtures.py", "forms.py", "managers.py"]
MAGNET_DPT_INCLUDE_PATHS = [] # relative paths that override MAGNET_DPT_IGNORE_PATHS rules
MAGNET_DPT_SKIP_METHODS = ["__str__", "__repr__", "save", "delete", "get_queryset", ...]
| Setting | Default | Description |
|---|---|---|
MAGNET_DPT_DOCS_OUTPUT_DIR |
docs/SRS |
Output dir for generate_docs |
MAGNET_DPT_BRD_OUTPUT_DIR |
docs/BRD |
Output dir for generate_brd |
MAGNET_DPT_GLOSSARY_PATH |
docs/GLOSSARY.md |
Shared glossary file |
MAGNET_DPT_MODEL |
claude-sonnet-4-20250514 |
Claude model used |
MAGNET_DPT_MAX_TOKENS |
4096 |
Max tokens per API response |
MAGNET_DPT_MAX_CONTEXT_CHARS |
40000 |
Max context chars sent to Claude (~10k tokens) |
MAGNET_DPT_REQUEST_DELAY_SECONDS |
15 |
Default delay between API calls |
MAGNET_DPT_MAX_RETRIES |
3 |
Retries on rate limit errors |
MAGNET_DPT_RETRY_BACKOFF |
60 |
Base wait per retry (seconds × attempt number) |
MAGNET_DPT_IGNORE_DIRS |
(see above) | Directory names excluded from scanning |
MAGNET_DPT_IGNORE_PATHS |
(see above) | Filenames/paths excluded from scanning |
MAGNET_DPT_INCLUDE_PATHS |
[] |
Relative paths that override IGNORE_PATHS rules |
MAGNET_DPT_SKIP_METHODS |
(see above) | Method names omitted from documentation |
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 magnet_dpt_doc_generator-0.1.0.tar.gz.
File metadata
- Download URL: magnet_dpt_doc_generator-0.1.0.tar.gz
- Upload date:
- Size: 31.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.3 Linux/6.17.0-19-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
553924ec6527f36bead78efc6650de491e60e2be199a2bd48d722f422d947caf
|
|
| MD5 |
a9c72dfb6e09cdbae97519f573a6657b
|
|
| BLAKE2b-256 |
7e0eaeefaa80cac9345377905a732790510ed3c00c328599f15a1c832f70bf44
|
File details
Details for the file magnet_dpt_doc_generator-0.1.0-py3-none-any.whl.
File metadata
- Download URL: magnet_dpt_doc_generator-0.1.0-py3-none-any.whl
- Upload date:
- Size: 37.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.12.3 Linux/6.17.0-19-generic
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aa725d5d5e6b539c59d282385fd9b5ef42710da6a256269d2ffa02f0f475172e
|
|
| MD5 |
6ad753a378e738f566d3f87bd98b3dd2
|
|
| BLAKE2b-256 |
5eefd295feb0a68df2ae51eb1b5c51002b08fcd46cba712cc61d0198a4eac8ea
|