Skip to main content

Swagger2 support for FastAPI framework

Project description

fastapi_swagger2

Swagger2 support for FastAPI

Package version Supported Python versions


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.8+

  • 0.0.3 - FastAPI >= 0.79.0, <= 0.98.0
  • 0.1.1 - FastAPI >= 0.99.0, <= 0.99.1
  • 0.2.4 - FastAPI >= 0.100.0

Installation

$ pip install fastapi_swagger2

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:

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

$ pip install "/path/to/fastapi_swagger2/repo[test,all]"

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastapi_swagger2-0.2.4.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

fastapi_swagger2-0.2.4-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_swagger2-0.2.4.tar.gz.

File metadata

  • Download URL: fastapi_swagger2-0.2.4.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: python-httpx/0.23.3

File hashes

Hashes for fastapi_swagger2-0.2.4.tar.gz
Algorithm Hash digest
SHA256 0020a1478d1d23d261cbb7972bebdba264a34de476dae5a8b916095be5055a9b
MD5 fb13c793aed4d67191fb43dbe70864c1
BLAKE2b-256 0cfe7ebc42f09a19b0a7063d05fada16fd54249f85019ff107b0f86b14f2a6ef

See more details on using hashes here.

File details

Details for the file fastapi_swagger2-0.2.4-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_swagger2-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 3e910fcdf10cf5a66bba4b5d047187b0387b0d692ac67cd6bd036871716dfea1
MD5 1f6482a9f01564c35b54716406e14017
BLAKE2b-256 ab965a10e2de99453e81175b7d5be53554e082b14ef21f05c9ab61ccd579f6a4

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page