Skip to main content

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.

PyPI version Python Support License: MIT CI codecov

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 schema
  • docs_directory (str): Path to markdown documentation directory
  • base_url (str, optional): Base URL for code samples
  • custom_headers (dict, optional): Custom headers for code samples
  • code_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 requests library
  • JavaScript - Using fetch API
  • TypeScript - With proper type annotations
  • Go - Using net/http package
  • 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

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes
  4. Add tests for your changes
  5. Run the test suite (pytest)
  6. Commit your changes (git commit -m 'Add amazing feature')
  7. Push to the branch (git push origin feature/amazing-feature)
  8. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastmarkdocs-0.1.4.tar.gz (26.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastmarkdocs-0.1.4-py3-none-any.whl (27.0 kB view details)

Uploaded Python 3

File details

Details for the file fastmarkdocs-0.1.4.tar.gz.

File metadata

  • Download URL: fastmarkdocs-0.1.4.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

Hashes for fastmarkdocs-0.1.4.tar.gz
Algorithm Hash digest
SHA256 f7fcd3b730974d9427269e13a25587a9aa071e33c2463a75a405801f82fbd859
MD5 d0db1d41f15de4b443d4fe158952dd14
BLAKE2b-256 c43c0aa1c2a2642a1b2a7612db9e82b7d48c6be23e13d5743e64e7a6459d553c

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastmarkdocs-0.1.4.tar.gz:

Publisher: publish.yml on danvatca/FastMarkDocs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastmarkdocs-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: fastmarkdocs-0.1.4-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

Hashes for fastmarkdocs-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 0611e320bc76d96038e0a7b8dfda625902accf4aaccf0d4ce23bc399675da5f2
MD5 5451564afce8d9a7a9dbcd5bcefbceaa
BLAKE2b-256 ea5577644afa1ed27dfdf6ddfce67eb011b150269446b8995d3826428c3ef4cd

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastmarkdocs-0.1.4-py3-none-any.whl:

Publisher: publish.yml on danvatca/FastMarkDocs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page