Stoplight Elements API Documentation Plugin for FastAPI
Installation
Install stoplight-fastapi using your preferred package manager:
Using uv (recommended)
uv add stoplight-fastapi
Using pip
pip install stoplight-fastapi
Requirements
- Python 3.10 or higher
- FastAPI 0.115.0 or higher
Quick Start
Basic Setup
from fastapi import FastAPI
from stoplight_fastapi import get_stoplight_api_reference
app = FastAPI(
title="My API",
description="Welcome to My Awesome API.",
version="1.0.0",
)
@app.get("/items/{item_id}")
def read_item(item_id: int, q: str = None):
"""Get an item by ID."""
return {"item_id": item_id, "q": q}
@app.get("/stoplight", include_in_schema=False)
def get_stoplight_html():
"""Render API documentation with Stoplight Elements."""
return get_stoplight_api_reference(
openapi_url=app.openapi_url,
title=app.title,
)
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=8000)
Then visit http://localhost:8000/stoplight to view your API documentation.
Advanced Configuration
Customize the Stoplight Elements UI with advanced options:
from stoplight_fastapi import get_stoplight_api_reference, StoplightConfig
@app.get("/docs", include_in_schema=False)
def get_stoplight_html():
"""Advanced Stoplight Elements configuration."""
return get_stoplight_api_reference(
openapi_url=app.openapi_url,
stoplight_config=StoplightConfig(
router="hash", # Enable hash-based routing for shareable links
layout="stacked", # Choose between 'sidebar', 'responsive', and 'stacked' layouts
# Additional Stoplight configuration options available
),
)
Live Example
uv run https://codeberg.org/naiwaaa/stoplight-fastapi/raw/branch/main/scripts/playground.py
Visit http://localhost:8000/stoplight to see Stoplight Elements in action.
Resources
Metadata
Release files for stoplight-fastapi 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| stoplight_fastapi-0.1.1.tar.gz | 5.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| stoplight_fastapi-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.4 kB
Release files / stoplight_fastapi-0.1.1.tar.gz
| Download URL | stoplight_fastapi-0.1.1.tar.gz |
|---|---|
| Size | 5.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b1e7f38b20af66ac288be2afc5179d757097d5b60c350e213283c81243407d86
|
|
BLAKE2b-256 checksum How to use checksums |
6dd91a389741c00a6c3b021d3232672404498495d88498bd30b6dbf14efcc49c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / stoplight_fastapi-0.1.1-py3-none-any.whl
| Download URL | stoplight_fastapi-0.1.1-py3-none-any.whl |
|---|---|
| Size | 5.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1874f9ce2e1c3e7ea61e066ee32bfd4075d8b411218daff6705465e599c4c826
|
|
BLAKE2b-256 checksum How to use checksums |
0e3c4e70edd8869464a3aed486145dc85ba4f5771ed1f2b7a2365ba11c0edf6e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.14 {"installer":{"name":"uv","version":"0.11.14","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|