Skip to main content

Swagger UI for Streamlit

Project description

st_swagger_ui

Streamlit component for embedding Swagger UI to display OpenAPI/Swagger specifications.

Features

  • Display OpenAPI/Swagger specifications from URL or local file
  • Configurable operation expansion (doc_expansion)
  • Enable/disable "Try it out" functionality (try_it_out_enabled)
  • Show/hide operation IDs (display_operation_id)
  • Control model rendering (default_model_rendering)
  • Custom CSS overrides for reduced indentation

Installation

uv add st_swagger_ui

or

pip install st_swagger_ui

Usage

Basic Usage

import streamlit as st
from st_swagger_ui import st_swagger_ui

# Load from URL
st_swagger_ui(url="https://petstore.swagger.io/v2/swagger.json")

Load from Local File

import json

with open("openapi.json") as f:
    spec = json.load(f)

st_swagger_ui(spec=spec)

Configuration Options

st_swagger_ui(
    url="https://petstore.swagger.io/v2/swagger.json",
    doc_expansion="list",           # "list" | "full" | "none"
    try_it_out_enabled=True,        # True | False | None
    display_operation_id=False,     # True | False | None
    default_model_rendering="example",  # "example" | "model" | None
)

Parameters

Parameter Type Default Description
url str None URL to fetch OpenAPI specification from
spec dict None OpenAPI specification as a Python dict
doc_expansion str None Default expansion: "list", "full", or "none"
try_it_out_enabled bool None Enable "Try it out" functionality
display_operation_id bool None Show operation IDs next to operation names
default_model_rendering str None Model display: "example" or "model"

Note: Either url or spec must be provided (mutually exclusive).

Examples

Full Expansion with Model View

st_swagger_ui(
    url="https://petstore.swagger.io/v2/swagger.json",
    doc_expansion="full",
    default_model_rendering="model"
)

Read-Only Mode (No "Try it out")

st_swagger_ui(
    url="https://api.example.com/openapi.json",
    try_it_out_enabled=False,
    display_operation_id=True
)

Load from FastAPI App

from fastapi import FastAPI
import fastapi.openapi.utils

app = FastAPI()

spec = fastapi.openapi.utils.get_openapi(
    title="My API",
    version="1.0.0",
    openapi_version="3.0.0",
    routes=app.routes,
)

st_swagger_ui(spec=spec, doc_expansion="list")

License

MIT

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

st_swagger_ui-0.1.1.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

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

st_swagger_ui-0.1.1-py3-none-any.whl (520.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: st_swagger_ui-0.1.1.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.27.0

File hashes

Hashes for st_swagger_ui-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2bf1dca60b4110e5ff57e2693efe73fd06df730c85621d5bdc901079fb2083d8
MD5 3b94cd196c735caf2725015c9e2b7a87
BLAKE2b-256 f410638b7ad5a33e0289bf1504c9bff133d0ee2acb2112729bf77f381e1bdcf6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for st_swagger_ui-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 46cd6810a210b992452188d2bb7ccd2f3f153869e834e9c5b21d8cd00d807c8e
MD5 4c17b3852889f43988995bd1b3e7d59d
BLAKE2b-256 825072c5db916df5928c2766822e2db4caadafc6cfd82baf616f5ecff2673a87

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