Generate Markdown API docs from Django/DRF OpenAPI schema for MkDocs
Project description
DRF to MkDocs
Generate beautiful, interactive Markdown API documentation from Django REST Framework OpenAPI schema for MkDocs.
Why you'll love it
- Zero-hassle docs: Beautiful, always-in-sync API docs straight from your codebase
- Model deep dive: Auto-generated model pages with fields, relationships, and choices
- Lightning-fast discovery: Interactive endpoint index with powerful filters and search
- Try-it-out: Interactive API testing directly in the documentation with request/response examples
- AI-powered: Optional AI-generated documentation with custom field generators(Wait for it...)
- DRF-native: Works with DRF Spectacular; no custom schema wiring needed
- MkDocs Material: Looks great out of the box with the Material theme
Installation
See the full installation guide in docs/installation.md.
Quick Start
- Configure your Django project:
# settings.py
INSTALLED_APPS = [
# ... your other apps
'drf_to_mkdoc',
]
# Required for OpenAPI schema generation
REST_FRAMEWORK = {
'DEFAULT_SCHEMA_CLASS': 'drf_to_mkdoc.utils.schema.AutoSchema',
}
SPECTACULAR_SETTINGS = {
'TITLE': 'Your API',
'DESCRIPTION': 'Your API description',
'VERSION': '1.0.0',
}
DRF_TO_MKDOC = {
'DJANGO_APPS': [
'users',
'products',
'orders',
'inventory',
],
# Optional: Override default paths
# 'DOCS_DIR': 'docs',
# 'CONFIG_DIR': 'docs/configs',
# 'MODEL_DOCS_FILE': 'docs/model-docs.json',
# 'DOC_CONFIG_FILE': 'docs/configs/doc_config.json',
# 'CUSTOM_SCHEMA_FILE': 'docs/configs/custom_schema.json',
# 'FIELD_GENERATORS': {
# 'email': 'faker.email',
# 'name': 'faker.name',
# 'created_at': 'datetime.now',
# },
# 'ENABLE_AI_DOCS': False,
}
-
Create MkDocs configuration:
Copy thedocs/mkdocs.ymlfile to your project root and customize it as needed. -
Build documentation:
python manage.py build_docs --settings=docs_settings
Configuration Options
The DRF_TO_MKDOC setting supports several configuration options:
DJANGO_APPS(required): List of Django app names to processDOCS_DIR: Directory where docs will be generated (default:docs)CONFIG_DIR: Directory for configuration files (default:docs/configs)FIELD_GENERATORS: Custom field value generators for better examplesENABLE_AI_DOCS: Enable AI-powered documentation features (default:False)PATH_PARAM_SUBSTITUTE_FUNCTION: Custom function for path parameter substitutionPATH_PARAM_SUBSTITUTE_MAPPING: Mapping for path parameter substitution
Available Commands
build_docs: Build the complete documentation site with MkDocsbuild_endpoint_docs: Build endpoint documentation from OpenAPI schemabuild_model_docs: Build model documentation from model JSON dataextract_model_data: Extract model data from Django model introspection and save as JSONgenerate_doc_json: Generate JSON context for new API endpoints to be documentedupdate_doc_schema: Update the final schema by copying the documented schema
What you get
See a detailed overview of generated files in docs/structure.md and a feature breakdown in docs/features.md.
Key Features
๐ Interactive API Testing (Try-Out)
- Live API testing: Test endpoints directly from the documentation
- Request builder: Interactive forms for parameters, headers, and request body
- Response viewer: Real-time response display with syntax highlighting
- Floating action button: Easy access to testing interface
- Multiple examples: Support for both empty and populated response examples
๐ค AI-Powered Documentation
- Custom field generators: Define custom value generators for specific fields
- AI documentation: Optional AI-generated documentation with context analysis
- Smart examples: Enhanced example generation for better API understanding
๐ Advanced Filtering & Search
- Multi-criteria filtering: Filter by app, HTTP method, path, and search terms
- Real-time search: Instant search across all endpoints
- Smart suggestions: Auto-complete for query parameters and field names
๐จ Beautiful UI
- Material Design: Modern, responsive interface with dark/light themes
- Interactive elements: Hover effects, animations, and smooth transitions
- Mobile-friendly: Fully responsive design for all devices
How it works
Under the hood, drf-to-mkdoc introspects your models and reads your DRF OpenAPI schema to generate clean, organized Markdown. Then MkDocs turns it into a polished static site. Always current, no manual updates.
Explore more
- Customizing endpoint docs:
docs/customizing_endpoints.md - Serving docs through Django (with permissions):
docs/serving_mkdocs_with_django.md
Dependencies
- Django >= 3.2, < 6.0
- Django REST Framework >= 3.12, < 4.0
- drf-spectacular >= 0.26.0
- PyYAML >= 6.0
- MkDocs >= 1.4.0
- MkDocs Material >= 9.0.0
- coreapi >= 2.3.0
Development
Setup Development Environment
git clone https://github.com/Shayestehhs/drf-to-mkdoc.git
cd drf-to-mkdoc
pip install -e ".[dev]"
Project Structure
drf-to-mkdoc/
โโโ drf_to_mkdoc/
โ โโโ conf/
โ โ โโโ defaults.py # Default configuration values
โ โ โโโ settings.py # Settings management
โ โโโ management/
โ โ โโโ commands/
โ โ โโโ build_docs.py # Build MkDocs site
โ โ โโโ build_endpoint_docs.py # Build endpoint documentation
โ โ โโโ build_model_docs.py # Build model documentation
โ โ โโโ extract_model_data.py # Extract model data from Django
โ โ โโโ generate_doc_json.py # Generate JSON context for AI docs
โ โ โโโ update_doc_schema.py # Schema updates
โ โโโ static/
โ โ โโโ drf-to-mkdoc/
โ โ โโโ javascripts/
โ โ โ โโโ try-out/ # Interactive API testing
โ โ โ โโโ endpoints-filter.js # Endpoint filtering
โ โ โโโ stylesheets/ # CSS for styling
โ โโโ templates/
โ โ โโโ endpoints/ # Endpoint documentation templates
โ โ โโโ model_detail/ # Model documentation templates
โ โ โโโ try-out/ # Interactive testing templates
โ โโโ utils/
โ โโโ ai_tools/ # AI-powered documentation features
โ โโโ commons/ # Shared utilities
โ โโโ extractors/ # Query parameter extraction
โ โโโ endpoint_detail_generator.py
โ โโโ endpoint_list_generator.py
โ โโโ model_detail_generator.py
โ โโโ model_list_generator.py
โ โโโ schema.py
โโโ docs/ # Generated documentation
โโโ pyproject.toml # Project configuration
โโโ README.md
License
This project is licensed under the MIT License - see the LICENSE file for details.
Recommendations
.gitignore Configuration
To avoid committing generated files to your repository, add the following to your .gitignore file:
# Documentation
/docs/endpoints/
/docs/models/
/docs/configs/doc-schema.yaml
# Build artifacts
/site/
This will ensure that only the source configuration and scripts are versioned, while the generated documentation is excluded.
docs_settings.py Best Practices
Create a separate docs_settings.py file that inherits from your main settings:
# docs_settings.py
from .settings import *
DRF_TO_MKDOC = {
'DJANGO_APPS': ['your_app1', 'your_app2'],
}
# Other doc settings...
Then use the --settings argument when running the build command:
python manage.py build_docs --settings=docs_settings
Project Organization
your-project/
โโโ settings.py # Main Django settings
โโโ docs_settings.py # Documentation-specific settings
โโโ mkdocs.yml # MkDocs configuration
โโโ docs/ # Generated documentation (gitignored)
โโโ site/ # Built site (gitignored)
Contributing
See CONTRIBUTING.md for detailed contribution guidelines.
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 drf_to_mkdoc-0.2.4.tar.gz.
File metadata
- Download URL: drf_to_mkdoc-0.2.4.tar.gz
- Upload date:
- Size: 94.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
067e050dad7a260b653a5243877b529b6c81db46be238ca4cf79904ef46c0a9e
|
|
| MD5 |
b13630c5a55f0fc24f1c802448afc7d6
|
|
| BLAKE2b-256 |
1d4c4ac57bb0f82af3c5fe0f42aadd555c3416e16dafd5e9103c58825ffdc2b1
|
Provenance
The following attestation bundles were made for drf_to_mkdoc-0.2.4.tar.gz:
Publisher:
publish.yaml on ShayestehHS/drf-to-mkdoc
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
drf_to_mkdoc-0.2.4.tar.gz -
Subject digest:
067e050dad7a260b653a5243877b529b6c81db46be238ca4cf79904ef46c0a9e - Sigstore transparency entry: 560437934
- Sigstore integration time:
-
Permalink:
ShayestehHS/drf-to-mkdoc@825987bd3d7553462da34e3a060df953ba426724 -
Branch / Tag:
refs/tags/v0.2.4 - Owner: https://github.com/ShayestehHS
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@825987bd3d7553462da34e3a060df953ba426724 -
Trigger Event:
push
-
Statement type:
File details
Details for the file drf_to_mkdoc-0.2.4-py3-none-any.whl.
File metadata
- Download URL: drf_to_mkdoc-0.2.4-py3-none-any.whl
- Upload date:
- Size: 125.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74528b4c38593f4c6152a59af975af055337cc7f396fcef08536ab52978f9621
|
|
| MD5 |
3191f5ef0d2c91ecc23cc6f36cd04987
|
|
| BLAKE2b-256 |
9a0bdae5949119fe56a3221eb56243acba0060fef66114fd6de394c55bb8ed03
|
Provenance
The following attestation bundles were made for drf_to_mkdoc-0.2.4-py3-none-any.whl:
Publisher:
publish.yaml on ShayestehHS/drf-to-mkdoc
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
drf_to_mkdoc-0.2.4-py3-none-any.whl -
Subject digest:
74528b4c38593f4c6152a59af975af055337cc7f396fcef08536ab52978f9621 - Sigstore transparency entry: 560437957
- Sigstore integration time:
-
Permalink:
ShayestehHS/drf-to-mkdoc@825987bd3d7553462da34e3a060df953ba426724 -
Branch / Tag:
refs/tags/v0.2.4 - Owner: https://github.com/ShayestehHS
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@825987bd3d7553462da34e3a060df953ba426724 -
Trigger Event:
push
-
Statement type: