Skip to main content

FastAPI versioning

Project description

fastapi_vers

API versioning concept for FastAPI

tests

pip install fastapi_vers
from fastapi import FastAPI
from fastapi_vers import API


api = API(
    "0.3",
    app_kwds={
        "all": {"title": "Versioned API", "version": "0.0"},
        "0.1": {"version": "0.1"},
        "0.2": {"version": "0.2"},
    }
)


@api.app.get("/")
async def root():
    return "Hello World!"


@api.app.get("/foo")
@api.version(["0.1-0.2"])
async def foo():
    return "This endpoint available only for 0.1, 0.2 api versions"


@api.app.get("/bar")
@api.version(["0.1-latest"])
async def bar():
    return "This endpoint available for 0.1, 0.2, 0.3 api versions"


app = FastAPI()
app.mount("/api", api.get_versioned_app())

"""
http://localhost:8000/api/latest

http://localhost:8000/api/0.1/foo
http://localhost:8000/api/0.2/foo

http://localhost:8000/api/0.1/bar
http://localhost:8000/api/0.2/bar
http://localhost:8000/api/0.3/bar
"""

Project details


Download files

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

Source Distribution

fastapi_vers-0.3.0.tar.gz (3.7 kB view hashes)

Uploaded Source

Built Distribution

fastapi_vers-0.3.0-py3-none-any.whl (3.9 kB view hashes)

Uploaded Python 3

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