Easy way to build versioning APIs by FastAPI
Project description
FastAPI Easy Versioning
This is a solution for building versioned APIs automatically using FastAPI. It enables automatic inheritance of endpoints from previous FastAPI sub-applications into newer versions based on configuration, and correctly reflects them in the OpenAPI schema.
Installation
pip install fastapi-easy-versioning
Usage
To implement versioning, use the VersioningMiddleware and the dependency factory versioning.
Example:
from fastapi import FastAPI, Depends
from fastapi_easy_versioning import VersioningMiddleware, versioning
app = FastAPI()
app_v1 = FastAPI(api_version=1)
app_v2 = FastAPI(api_version=2)
app.mount("/v1", app_v1)
app.mount("/v2", app_v2)
app.add_middleware(VersioningMiddleware)
@app_v1.get('/only-v1', dependencies=[Depends(versioning(until=1))])
def only_v1() -> str:
return "Available only in version v1"
@app_v1.get('/all-versions', dependencies=[Depends(versioning())])
def all_versions() -> str:
return "Available in all versions starting from v1"
@app_v2.get('/from-v2', dependencies=[Depends(versioning())])
def from_v2() -> str:
return "Available starting from v2 and in all future versions"
The endpoint /only-v1 is available only in version v1 at /v1/only-v1.
The endpoint /from-v2 becomes available starting from version v2 at /v2/from-v2 and is automatically inherited in all subsequent versions.
The endpoint /all-versions, defined in v1, is accessible at both /v1/all-versions and /v2/all-versions due to the inheritance mechanism.
Using the versioning dependency factory, you can specify the last version in which an endpoint remains available by setting the until parameter to a version number. If until is set to None or omitted, the endpoint will be available in the version it was declared and in all later versions.
To associate a sub-application with a specific version, use the api_version parameter when creating the FastAPI instance. It must be an integer. Sub-applications without the api_version parameter will be ignored during versioning processing.
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastapi_easy_versioning-0.1.0.tar.gz.
File metadata
- Download URL: fastapi_easy_versioning-0.1.0.tar.gz
- Upload date:
- Size: 5.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1c9a869e79b3a5b894425f52266904a7e3961892bdcc61302f9663bdff8c40bc
|
|
| MD5 |
b579bd70477f4c5058f5664319d5da7c
|
|
| BLAKE2b-256 |
402e19b4ea71506a7fe8e0d66a0cd15756183794e792e31af614b3155fb25c51
|
File details
Details for the file fastapi_easy_versioning-0.1.0-py3-none-any.whl.
File metadata
- Download URL: fastapi_easy_versioning-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: uv/0.8.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed9efac6e16ca0492d1962d76ff252963b0c6d795084e1ac907d6c8d3db1f721
|
|
| MD5 |
a8c110acdd2b606e3011c7dac074b258
|
|
| BLAKE2b-256 |
b7c26788b1474e967b0e921c9203feb440800e86a18e8f691487571e7739fed0
|