A powerful library for enhancing FastAPI applications with rich markdown-based API documentation
Project description
FastMarkDocs
A powerful library for enhancing FastAPI applications with rich markdown-based API documentation. Transform your API documentation workflow with beautiful, maintainable markdown files that generate comprehensive OpenAPI enhancements.
Features
✨ Rich Documentation: Transform markdown files into comprehensive API documentation
🔧 OpenAPI Enhancement: Automatically enhance your OpenAPI/Swagger schemas
🌍 Multi-language Code Samples: Generate code examples in Python, JavaScript, TypeScript, Go, Java, PHP, Ruby, C#, and cURL
📝 Markdown-First: Write documentation in familiar markdown format
🎨 Customizable Templates: Use custom templates for code generation
⚡ High Performance: Built-in caching and optimized processing
🧪 Well Tested: Comprehensive test suite with 100+ tests
Quick Start
Installation
pip install fastmarkdocs
Basic Usage
from fastapi import FastAPI
from fastmarkdocs import enhance_openapi_with_docs
app = FastAPI()
# Enhance your OpenAPI schema with markdown documentation
enhanced_schema = enhance_openapi_with_docs(
openapi_schema=app.openapi(),
docs_directory="docs/api",
base_url="https://api.example.com",
custom_headers={"Authorization": "Bearer token123"}
)
# Update your app's OpenAPI schema
app.openapi_schema = enhanced_schema
Documentation Structure
Create markdown files in your docs directory:
docs/api/
├── users.md
├── authentication.md
└── orders.md
Example markdown file (users.md):
# User Management API
## GET /users
Retrieve a list of all users in the system.
### Description
This endpoint returns a paginated list of users with their basic information.
### Parameters
- `page` (integer, optional): Page number for pagination (default: 1)
- `limit` (integer, optional): Number of users per page (default: 10)
### Response Examples
```json
{
"users": [
{
"id": 1,
"username": "john_doe",
"email": "john@example.com"
}
],
"total": 100,
"page": 1,
"limit": 10
}
Code Samples
import requests
response = requests.get("https://api.example.com/users")
users = response.json()
const response = await fetch('https://api.example.com/users');
const users = await response.json();
## Advanced Features
### Custom Code Generation
```python
from fastmarkdocs import CodeSampleGenerator
generator = CodeSampleGenerator(
base_url="https://api.example.com",
custom_headers={"X-API-Key": "your-key"},
code_sample_languages=["python", "javascript", "go"]
)
# Generate samples for a specific endpoint
samples = generator.generate_samples_for_endpoint(endpoint_data)
Template Customization
from fastmarkdocs import DocumentationLoader
loader = DocumentationLoader(
docs_directory="docs/api",
custom_templates={
"python": """
import requests
def {method_lower}_{path_safe}():
response = requests.{method_lower}("{url}")
return response.json()
"""
}
)
Caching Configuration
from fastmarkdocs import DocumentationLoader
loader = DocumentationLoader(
docs_directory="docs/api",
enable_caching=True,
cache_ttl=3600 # 1 hour
)
API Reference
Core Functions
enhance_openapi_with_docs()
Enhance an OpenAPI schema with markdown documentation.
Parameters:
openapi_schema(dict): The original OpenAPI schemadocs_directory(str): Path to markdown documentation directorybase_url(str, optional): Base URL for code samplescustom_headers(dict, optional): Custom headers for code samplescode_sample_languages(list, optional): Languages for code generation
Returns: Enhanced OpenAPI schema (dict)
Classes
DocumentationLoader
Load and process markdown documentation files.
loader = DocumentationLoader(
docs_directory="docs/api",
enable_caching=True,
cache_ttl=3600,
custom_templates={}
)
# Load all documentation
docs = loader.load_documentation()
CodeSampleGenerator
Generate code samples for API endpoints.
generator = CodeSampleGenerator(
base_url="https://api.example.com",
custom_headers={"Authorization": "Bearer token"},
code_sample_languages=["python", "javascript"]
)
# Generate samples
samples = generator.generate_samples_for_endpoint(endpoint)
OpenAPIEnhancer
Enhance OpenAPI schemas with documentation data.
enhancer = OpenAPIEnhancer(
base_url="https://api.example.com",
custom_headers={"X-API-Key": "key"},
code_sample_languages=["python", "go"]
)
# Enhance schema
enhanced = enhancer.enhance_openapi_schema(schema, documentation)
Supported Languages
The library supports code generation for:
- Python - Using
requestslibrary - JavaScript - Using
fetchAPI - TypeScript - With proper type annotations
- Go - Using
net/httppackage - Java - Using
HttpURLConnection - PHP - Using
cURL - Ruby - Using
net/http - C# - Using
HttpClient - cURL - Command-line examples
Error Handling
The library provides comprehensive error handling:
from fastmarkdocs.exceptions import (
DocumentationLoadError,
CodeSampleGenerationError,
OpenAPIEnhancementError,
ValidationError
)
try:
docs = loader.load_documentation()
except DocumentationLoadError as e:
print(f"Failed to load documentation: {e}")
Testing
Run the test suite:
# Install development dependencies
pip install -e ".[dev]"
# Run all tests
pytest
# Run with coverage
pytest --cov=fastmarkdocs
# Run specific test categories
pytest -m unit
pytest -m integration
Contributing
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Add tests for your changes
- Run the test suite (
pytest) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Documentation Development
To build and test the documentation locally:
# First time setup
./build-docs.sh setup
# Build and serve locally with live reload
./build-docs.sh serve
# Or using Make
make -f Makefile.docs docs-serve
The documentation will be available at http://localhost:4000 with automatic reloading when you make changes.
See docs/BUILD.md for detailed documentation build instructions.
Development Setup
# Clone the repository
git clone https://github.com/yourusername/fastmarkdocs.git
cd fastmarkdocs
# Install Poetry (if not already installed)
curl -sSL https://install.python-poetry.org | python3 -
# Install dependencies
poetry install
# Activate virtual environment
poetry shell
# Run tests
pytest
License
This project is licensed under the MIT License - see the LICENSE file for details.
Changelog
See CHANGELOG.md for a detailed history of changes.
Support
Related Projects
- FastAPI - The web framework this library enhances
- OpenAPI - The specification this library extends
- Swagger UI - The UI that displays the enhanced 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 fastmarkdocs-0.1.3.tar.gz.
File metadata
- Download URL: fastmarkdocs-0.1.3.tar.gz
- Upload date:
- Size: 26.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5469d84117bc3588d97d81ed3f6340918d9195c80e1934431085ffd702e871f8
|
|
| MD5 |
09b32ce6445005774e1164d29840f6bb
|
|
| BLAKE2b-256 |
6cc106db2c4bc01253496fbccba06be8a4ff01498849731e07aa2426a9f32ee9
|
Provenance
The following attestation bundles were made for fastmarkdocs-0.1.3.tar.gz:
Publisher:
publish.yml on danvatca/FastMarkDocs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastmarkdocs-0.1.3.tar.gz -
Subject digest:
5469d84117bc3588d97d81ed3f6340918d9195c80e1934431085ffd702e871f8 - Sigstore transparency entry: 233044294
- Sigstore integration time:
-
Permalink:
danvatca/FastMarkDocs@c223e53f7db753537fa48bbd7777267b1b539d1c -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/danvatca
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c223e53f7db753537fa48bbd7777267b1b539d1c -
Trigger Event:
release
-
Statement type:
File details
Details for the file fastmarkdocs-0.1.3-py3-none-any.whl.
File metadata
- Download URL: fastmarkdocs-0.1.3-py3-none-any.whl
- Upload date:
- Size: 27.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
198cfe5a1961d9e63c9051f3c304fe02a89aacd4e9b239c9c3b8edb926438763
|
|
| MD5 |
10cb167007e98e676f330cf1644e5780
|
|
| BLAKE2b-256 |
6070b34a3ee892d5e7c2433b43236770102ee7bc56b0936cbe809eaf9a0b260c
|
Provenance
The following attestation bundles were made for fastmarkdocs-0.1.3-py3-none-any.whl:
Publisher:
publish.yml on danvatca/FastMarkDocs
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastmarkdocs-0.1.3-py3-none-any.whl -
Subject digest:
198cfe5a1961d9e63c9051f3c304fe02a89aacd4e9b239c9c3b8edb926438763 - Sigstore transparency entry: 233044357
- Sigstore integration time:
-
Permalink:
danvatca/FastMarkDocs@c223e53f7db753537fa48bbd7777267b1b539d1c -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/danvatca
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@c223e53f7db753537fa48bbd7777267b1b539d1c -
Trigger Event:
release
-
Statement type: