Seamlessly integrate Stoplight Elements for beautiful, interactive API documentation in FastAPI.
Project description
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
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 stoplight_fastapi-0.1.0.tar.gz.
File metadata
- Download URL: stoplight_fastapi-0.1.0.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2c2612ac5d7a2ea0be6e8d806465dde508030552aff9be83ed04bbd252b2a3ee
|
|
| MD5 |
86255aef02ad8d9724c152b465f9a074
|
|
| BLAKE2b-256 |
a685478eadf058b1f00a2669cdfc55dc307950633438272460c6032915abf90c
|
File details
Details for the file stoplight_fastapi-0.1.0-py3-none-any.whl.
File metadata
- Download URL: stoplight_fastapi-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a78d8ee90a0c69f2fbeb85dc6028fe5c6615ebf6c7d9e6ce8890f6e6b4795c68
|
|
| MD5 |
d7187acadb2b09507821bd35c6b3fac4
|
|
| BLAKE2b-256 |
586e9146cb89e24a1ab35abd69e5ac93f792cd4b32bfe325b729915d9646583e
|