fastapi_swagger2
Swagger2 support for FastAPI
Reason behind this library:
Few API GW services like Google Cloud API GW still support only Swagger 2.0 spec. Since FastAPI only supports OAS3, it is a challenge. Converting from OAS3 to Swagger 2.0 requires some manual steps which would hinder CI/CD.
Requirements
Python 3.10+
- 0.4.4 - FastAPI >= 0.140.7
- 0.4.3 - FastAPI >= 0.140.3, < 0.140.7
- 0.4.2 - FastAPI >= 0.140.0, < 0.140.3
- 0.4.1 - FastAPI >= 0.137.2, < 0.140.0
- 0.4.0 - FastAPI >= 0.137.0, <= 0.137.1
- 0.3.5 - FastAPI >= 0.129.0, < 0.137.0
- 0.3.4 - FastAPI >= 0.129.0 (last tested against 0.133.1)
- 0.3.3 - FastAPI >= 0.128.4, <= 0.128.8 (FastAPI has dropped Python 3.9 support since 0.129.1)
- 0.3.2 - FastAPI >= 0.128.0, <= 0.128.3
- 0.3.1 - FastAPI >= 0.123.9, <= 0.127.1 + Pydantic v1/v2 (Since FastAPI 0.126.1, Pydantic v1 is deprecated)
- 0.3.0 - FastAPI >= 0.119.0, <= 0.123.8 + Pydantic v1/v2
- 0.2.7 - FastAPI >= 0.100.0, < 0.119.0 + Pydantic v1/v2
- 0.2.4 - FastAPI >= 0.100.0
- 0.1.1 - FastAPI >= 0.99.0, <= 0.99.1
- 0.0.3 - FastAPI >= 0.79.0, <= 0.98.0
Installation
$ pip install fastapi_swagger2
Development
$ uv sync --extra dev --extra test --extra all
Example
from typing import Union
from fastapi import FastAPI
from fastapi_swagger2 import FastAPISwagger2
app = FastAPI()
FastAPISwagger2(app)
@app.get("/")
def read_root():
return {"Hello": "World"}
@app.get("/items/{item_id}")
def read_item(item_id: int, q: Union[str, None] = None):
return {"item_id": item_id, "q": q}
This adds following endpoints:
- http://localhost:8000/swagger2.json
- http://localhost:8000/swagger2/docs
- http://localhost:8000/swagger2/redoc
Generate spec for CI/CD
import os
import yaml
from app.main import app
URL = os.environ["CLOUD_RUN_URL"]
app.servers.append(URL)
spec = app.swagger2()
spec['x-google-backend'] = {'address': URL}
print(yaml.dump(spec))
Development
$ uv sync --extra dev --extra test --extra all
Metadata
Release files for fastapi_swagger2 0.4.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fastapi_swagger2-0.4.4.tar.gz | 11.6 kB | Without provenance | Details for fastapi_swagger2-0.4.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fastapi_swagger2-0.4.4-py3-none-any.whl | Python 3 | none | any | Details for fastapi_swagger2-0.4.4-py3-none-any.whl |
Total release size: 24.7 kB
Release files / fastapi_swagger2-0.4.4.tar.gz
| Download URL | fastapi_swagger2-0.4.4.tar.gz |
|---|---|
| Size | 11.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b675d95d588b1eec27d230f22e4e133cd3cd61d55bfce61f313b243f368c7539
|
|
BLAKE2b-256 checksum How to use checksums |
47ddfe98bb9db78171cf25531f076995942cb4561087bd1c55f0f72199a6b611
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Release files / fastapi_swagger2-0.4.4-py3-none-any.whl
| Download URL | fastapi_swagger2-0.4.4-py3-none-any.whl |
|---|---|
| Size | 13.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5a3901c0f1e04fa2686f2c5d40623cc89c96586c0c77f0c43d44def577478b6f
|
|
BLAKE2b-256 checksum How to use checksums |
12d59bc3a581bd76766eff00c2a24b35c92568bdfffdd68fbfa38e00e3807480
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.11.16 {"installer":{"name":"uv","version":"0.11.16","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
|
Security for fastapi_swagger2 0.4.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.