API versionizer for FastAPI web applications
Project description
FastAPI Versionizer
Credit
This was inspired by fastapi_versioning.
This project fixes some of the issues with fastapi_versioning
and adds some additional features.
Installation
pip install fastapi-versionizer
Examples
You can find examples in the examples directory.
Details
- Routes can be annotated using the
@api_version
decorator- This essentially says, "This route is available from version (major, minor) onward, until a new version of the route is defined."
- Use the
versionize
function on your FastAPI app to perform the versionizing magic- Each version results in a new mounted FastAPI sub-application with a version prefix you define
- Unlike
fastapi_versioning
, this does not return a new FastAPI app, but applies the versioning directly to the app you provide - You can generate a "latest" alias for the latest version using
enable_latest
andlatest_prefix
- You can customize your OpenAPI schemas at runtime using
get_openapi
- This will be used to override the
openapi
function of all versioned FastAPI sub-applications
- This will be used to override the
- You can generate your own custom "main" docs page using
get_main_docs
and eithermain_docs_url
ordocs_url
- You can generate a Swagger/Redoc page for this, which exposes a single auto-generated "/versions" endpoint
- Or you can generate your own custom HTML page
- By default, no main docs page is generated
- See the Advanced Example for more details
- You can generate each versioned Swagger page using
get_docs
anddocs_url
- This is useful if you need to want to customize your Swagger HTML using
fastapi.openapi.docs.get_swagger_ui_html
- See the Advanced Example for more details
- This is useful if you need to want to customize your Swagger HTML using
- You can generate each versioned Redoc page using
get_redoc
andredoc_url
- This is useful if you need to want to customize your Redoc HTML using
fastapi.openapi.docs.get_redoc_html
- The usage of this is very similar to
get_docs
- This is useful if you need to want to customize your Redoc HTML using
- You can pass additional
kwargs
that will be supplied to each versioned sub-application- Note:
app.title
andapp.description
are automatically supplied to each versioned sub-application - For all other FastAPI parameters, these must be passed via
kwargs
- If you want a custom title and description for each versioned docs page, you can use
get_docs
and/orget_redoc
- Note: If you want docs pages to be generated, you must pass either
docs_url
orredoc_url
as kwargs - Note: If you want to specify custom
responses
, these must be defined on your FastAPI app (not viakwargs
)- See the Advanced Example for more details
- Note:
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
Close
Hashes for fastapi_versionizer-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 087c6125bbc7a3d3d48169765e2947440dd194c95d211a0e2236352cdfbfa045 |
|
MD5 | b403a360febfc4fdead5ef6467e61767 |
|
BLAKE2b-256 | f16a2a1877d9e15e9940aeb1324c32de9d2f128d685513b8e127e9ca1357be14 |