Skip to main content

Seamlessly integrate Stoplight Elements for beautiful, interactive API documentation in FastAPI.

Project description

Stoplight Elements API Documentation Plugin for FastAPI

Package - Version Package - Supported Python Versions Package - License

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

demo

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


Download files

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

Source Distribution

stoplight_fastapi-0.1.1.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

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

stoplight_fastapi-0.1.1-py3-none-any.whl (5.8 kB view details)

Uploaded Python 3

File details

Details for the file stoplight_fastapi-0.1.1.tar.gz.

File metadata

  • Download URL: stoplight_fastapi-0.1.1.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for stoplight_fastapi-0.1.1.tar.gz
Algorithm Hash digest
SHA256 b1e7f38b20af66ac288be2afc5179d757097d5b60c350e213283c81243407d86
MD5 f2688c515938ba38cf52552e3ea8d2ab
BLAKE2b-256 6dd91a389741c00a6c3b021d3232672404498495d88498bd30b6dbf14efcc49c

See more details on using hashes here.

File details

Details for the file stoplight_fastapi-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: stoplight_fastapi-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.8 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for stoplight_fastapi-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1874f9ce2e1c3e7ea61e066ee32bfd4075d8b411218daff6705465e599c4c826
MD5 c07f2cdfc34ebf9e2b8d78dc4c2894d6
BLAKE2b-256 0e3c4e70edd8869464a3aed486145dc85ba4f5771ed1f2b7a2365ba11c0edf6e

See more details on using hashes here.

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