Skip to content

georgekhananaev/fastapi-docshield

Repository files navigation

FastAPI DocShield

A simple FastAPI integration to protect documentation endpoints with HTTP Basic Authentication.

PyPI version License: MIT Python Versions Tests Status UV Compatible

About

Protect FastAPI's /docs, /redoc, and /openapi.json endpoints with HTTP Basic Authentication.

Installation

From PyPI

# Install with pip
pip install fastapi-docshield

# Or with uv
uv pip install fastapi-docshield

From Source

git clone https://github.com/georgekhananaev/fastapi-docshield.git
cd fastapi-docshield
pip install -e .

Quick Usage

from fastapi import FastAPI
from fastapi_docshield import DocShield

app = FastAPI()

@app.get("/")
def read_root():
    return {"Hello": "World"}

# Add protection to docs
DocShield(
    app=app,
    credentials={"admin": "password123"}
)

Running Demo

# Run the demo app
python demo.py

# Visit http://localhost:8000/docs
# Username: admin
# Password: password123

Running Tests

# Install test dependencies
pip install pytest httpx

# Run all tests
pytest

# Run with coverage
pytest --cov=fastapi_docshield

Features

  • Protect Swagger UI, ReDoc, and OpenAPI JSON endpoints
  • Customizable endpoint URLs
  • Multiple username/password combinations
  • Tested on Python 3.7-3.13
  • Compatible with uv package manager

License

MIT License - Copyright (c) 2025 George Khananaev

About

A simple FastAPI integration to protect documentation endpoints with HTTP Basic Authentication.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages