A simple FastAPI integration to protect documentation endpoints with HTTP Basic Authentication.
Protect FastAPI's /docs
, /redoc
, and /openapi.json
endpoints with HTTP Basic Authentication.
# Install with pip
pip install fastapi-docshield
# Or with uv
uv pip install fastapi-docshield
git clone https://github.com/georgekhananaev/fastapi-docshield.git
cd fastapi-docshield
pip install -e .
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"}
)
# Run the demo app
python demo.py
# Visit http://localhost:8000/docs
# Username: admin
# Password: password123
# Install test dependencies
pip install pytest httpx
# Run all tests
pytest
# Run with coverage
pytest --cov=fastapi_docshield
- 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
MIT License - Copyright (c) 2025 George Khananaev