Skip to main content

Fastapi versioning package with accept header

Project description

FastAPI versioning library

Test Coverage MyPy Strict Supported versions downloads GitHub stars

This package adds versioning by Accept-header into FastAPI

Quickstart:

Installation

$ pip install fast-version

Defining app and routes

import fastapi

from fast_version import VersionedAPIRouter, init_fastapi_versioning


VERSION_HEADER: str = "application/vnd.some.name+json"
ROUTER_OBJ = VersionedAPIRouter()


@ROUTER_OBJ.get("/test/")
async def test_get() -> dict:
    return {"version": (1, 0)}


@ROUTER_OBJ.get("/test/")
@ROUTER_OBJ.set_api_version((2, 0))
async def test_get_v2() -> dict:
    return {"version": (2, 0)}


app = fastapi.FastAPI()
app.include_router(ROUTER_OBJ)
init_fastapi_versioning(app=app, vendor_media_type=VERSION_HEADER)

Query Examples

# call 1.0 version
curl -X 'GET' 'https://test.ru/test/' -H 'accept: application/vnd.some.name+json; version=1.0'

curl -X 'GET' 'https://test.ru/test/' -H 'accept: application/vnd.some.name+json'

curl -X 'GET' 'https://test.ru/test/'

# call 2.0 version
curl -X 'GET' 'https://test.ru/test/' -H 'accept: application/vnd.some.name+json; version=2.0'

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

fast_version-1.2.3.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

fast_version-1.2.3-py3-none-any.whl (6.0 kB view details)

Uploaded Python 3

File details

Details for the file fast_version-1.2.3.tar.gz.

File metadata

  • Download URL: fast_version-1.2.3.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.4.17

File hashes

Hashes for fast_version-1.2.3.tar.gz
Algorithm Hash digest
SHA256 52605d8890d11b553d8ff21b61f6962931694e646b6fa338f6ec847195aa1203
MD5 c3174e4b6b006f0aeb8acea6ca120e76
BLAKE2b-256 191a6f6a5b3805d3fba28ca5f88b1d12a8bfea468b92fe593995a11f1ca5284d

See more details on using hashes here.

File details

Details for the file fast_version-1.2.3-py3-none-any.whl.

File metadata

File hashes

Hashes for fast_version-1.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 13de4a0802476288329b9211ec15e240d1985a0fbb9665698904e42db74dd25d
MD5 6e9c0316d9ade6d146b6471ca77a0d2f
BLAKE2b-256 fadd8eb3b7c7a22a610bce15e76bc3a533f26ccd146b55232b610422cefe3488

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