api versioning for fastapi web applications
Project description
fastapi-versioning
api versioning for fastapi web applications
Examples
from fastapi import FastAPI
from fastapi_versioning import VersionedFastAPI, version
app = FastAPI(title='My App')
@app.get('/greet')
@version(1, 0)
def greet():
return 'Hello'
@app.get('/greet')
@version(1, 1)
def greet():
return 'Hi'
app = VersionedFastAPI(app)
this will generate two endpoints:
/v1_0/greet
/v1_1/greet
as well as:
/docs
/v1_0/docs
/v1_1/docs
/v1_0/openapi.json
/v1_1/openapi.json
Try it out:
pip install pipenv
pipenv install --dev
pipenv run uvicorn example.app:app
Usage without minor version
from fastapi import FastAPI
from fastapi_versioning import VersionedFastAPI, version
app = FastAPI(title='My App')
@app.get('/greet')
@version(1)
def greet():
return 'Hello'
@app.get('/greet')
@version(2)
def greet():
return 'Hi'
app = VersionedFastAPI(app,
version_format='{major}',
prefix_format='/v{major}')
this will generate two endpoints:
/v1/greet
/v2/greet
as well as:
/docs
/v1/docs
/v2/docs
/v1/openapi.json
/v2/openapi.json
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for fastapi_versioning-0.4.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 200f90e4f7475d7166bc8b8f3277e55b84faba4d6be9f0a7b0bd73c47c60f9e2 |
|
MD5 | b06836855379ae68689953fbb1a36567 |
|
BLAKE2b-256 | 3135d94a76150fc8e4bbf534306293fa8be1fbfe22ccb3f655806dc56f7d9cc3 |