Metadata-Version: 2.4
Name: st_swagger_ui
Version: 0.1.1
Summary: Swagger UI for Streamlit
Project-URL: Homepage, https://github.com/quxiaowei/st-swagger-ui
Project-URL: Repository, https://github.com/quxiaowei/st-swagger-ui.git
Project-URL: Issues, https://github.com/quxiaowei/st-swagger-ui/issues
Author-email: qu xiaowei <quxw.work@gmail.com>
License-Expression: MIT
License-File: LICENSE
Keywords: api,documentation,openapi,streamlit,swagger
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Requires-Dist: streamlit>=1.51
Provides-Extra: devel
Requires-Dist: playwright==1.48.0; extra == 'devel'
Requires-Dist: pytest-playwright-snapshot==1.0; extra == 'devel'
Requires-Dist: pytest-rerunfailures==12.0; extra == 'devel'
Requires-Dist: pytest==7.4.0; extra == 'devel'
Requires-Dist: requests==2.31.0; extra == 'devel'
Requires-Dist: wheel; extra == 'devel'
Description-Content-Type: text/markdown

# 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

```sh
uv add st_swagger_ui
```

or

```sh
pip install st_swagger_ui
```

## Usage

### Basic Usage

```python
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

```python
import json

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

st_swagger_ui(spec=spec)
```

### Configuration Options

```python
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

```python
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")

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

#### Load from FastAPI App

```python
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
