Metadata-Version: 2.4
Name: theneo-fastapi
Version: 0.1.0
Summary: FastAPI integration for Theneo API Reference
Author-email: Theneo <hello@theneo.io>
License: MIT
Project-URL: Homepage, https://github.com/Theneo-Inc/theneo-reference-api
Project-URL: Repository, https://github.com/Theneo-Inc/theneo-reference-api
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: FastAPI
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.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Documentation
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.8
Description-Content-Type: text/markdown
Requires-Dist: fastapi>=0.100.0

# theneo-fastapi

FastAPI integration for the **Theneo API Reference** viewer.

Serves a self-contained HTML page + bundled JS/CSS that renders your OpenAPI spec with the Theneo UI.

## Installation

```bash
pip install theneo-fastapi
```

**In this monorepo** (development):

```bash
# From the repo root — build the JS bundle first
yarn install
yarn build

# Copy built assets into the Python package
bash integrations/python/fastapi/build.sh

# Install the Python package in editable mode
pip install -e integrations/python/fastapi
```

See the [root README](../../../README.md) and [FastAPI example](../../../examples/fastapi-example/README.md).

## Usage

### Quick — `get_theneo_html`

Return the HTML page yourself in any route:

```python
from fastapi import FastAPI
from fastapi.responses import HTMLResponse
from starlette.staticfiles import StaticFiles
from theneo_fastapi import get_theneo_html

app = FastAPI()

@app.get("/docs", response_class=HTMLResponse, include_in_schema=False)
async def docs():
    return get_theneo_html(openapi_url="/openapi.json", title="My API")

# Mount the bundled JS/CSS assets
import theneo_fastapi, pathlib
assets_dir = pathlib.Path(theneo_fastapi.__file__).parent / "assets"
app.mount("/theneo-assets", StaticFiles(directory=str(assets_dir)), name="theneo-assets")
```

### Router factory — `create_theneo_router`

Creates a router + static mount in one call:

```python
from fastapi import FastAPI
from theneo_fastapi import create_theneo_router

app = FastAPI(docs_url=None, redoc_url=None)

router, static = create_theneo_router(openapi_url="/openapi.json", title="My API")
app.include_router(router)
app.mount("/theneo-assets", static, name="theneo-assets")
```

Visit `http://localhost:8000/docs`.

## `get_theneo_html(**kwargs)`

Returns a complete HTML string.

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `openapi_url` | `str \| None` | `None` | URL the client fetches for the OpenAPI document. |
| `title` | `str` | `"API Reference"` | `<title>` and header text. |
| `spec` | `dict \| None` | `None` | Inline OpenAPI object. If `openapi_url` is also set, the URL wins. |
| `assets_base` | `str` | `"/theneo-assets"` | URL prefix for `theneo.umd.js` and `style.css`. |

## `create_theneo_router(**kwargs)`

Returns `(APIRouter, StaticFiles)`.

Same parameters as `get_theneo_html` plus:

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `assets_path` | `str` | `"/theneo-assets"` | Mount path for assets (must match `assets_base`). |

## Assets

The bundled `theneo.umd.js` and `style.css` live in `theneo_fastapi/assets/`. They are copied from `@theneo/vanilla/dist` by `build.sh` (see installation above).

## Requirements

- Python >= 3.8
- FastAPI >= 0.100.0
