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 pip install st_swagger_ui
Development install (editable)
When developing this component locally, install it in editable mode:
uv pip install -e . --force-reinstall
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")
Build Instructions
To package this component for distribution:
1. Build Frontend Assets
cd st_swagger_ui/frontend
npm install
npm run build
2. Build Python Wheel
From the project root:
uv build
This creates a dist/ directory containing:
dist/st_swagger_ui-<version>-py3-none-any.whldist/st_swagger_ui-<version>.tar.gz(sdist)
Requirements
- Python: >= 3.10
- Node.js: >= 24 (LTS)
- npm: Latest version (bundled with Node.js)
Development
Frontend Development
The frontend is built with:
- React 18
- TypeScript
- Vite
- swagger-ui-react
To run in development mode:
cd st_swagger_ui/frontend
npm run dev
Project Structure
st_swagger_ui/
├── st_swagger_ui/
│ ├── __init__.py # Python component
│ └── frontend/
│ ├── src/
│ │ ├── index.tsx # React entry point
│ │ └── swagger-ui-overrides.css # Custom CSS
│ ├── package.json
│ ├── vite.config.ts
│ └── build/ # Generated build output
├── pyproject.toml
├── README.md
└── example.py
License
MIT
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 st_swagger_ui-0.1.0.tar.gz.
File metadata
- Download URL: st_swagger_ui-0.1.0.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.27.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b7cfcee489816e02d59bd58a4af1c311c2c08e7010b071da96c2c889d87ba072
|
|
| MD5 |
ecccf2b9087470f1dec6904b0441a436
|
|
| BLAKE2b-256 |
520d7bd79425b405467ccaf8158d9db452abb42e7ec93032cc91841d151bbe66
|
File details
Details for the file st_swagger_ui-0.1.0-py3-none-any.whl.
File metadata
- Download URL: st_swagger_ui-0.1.0-py3-none-any.whl
- Upload date:
- Size: 521.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.27.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
103f28d994e8b707ec5e663ab4e02b06d9b65c2b43006d4399b8085e39b1d076
|
|
| MD5 |
988109ea86e50f33e3fcaee1bcc71c0f
|
|
| BLAKE2b-256 |
0b3e1be50e2aa3b73de3529238e70aad2107f478ccf36c74746caaaa1c97b265
|