Faster FastAPI start-up time for Projects with many nested routers
Project description
fastapi-deferred-init
The Problem
When using nested routers in a FastAPI project its start-up time can get long quite fast. That is because every router re-calculates the routes defined by a nested router when including it and the pre-calculated values by the nested router never get used. In short: values in nested routers are calculated although they will never be used.
The Solution
This library provides a modified APIRoute that defers the calculation of values to the first actual attribute access. A router which uses the route as a default is also provided.
Caveat
When using the deferred APIRoute on every layer of the app, startup errors are deferred to the first time a route is called. So errors related to route registration might go undetected if the route is not tested at least once.
Pull Request
I created a pull request to merge this change back into FastAPI: https://github.com/tiangolo/fastapi/pull/10589
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
Hashes for fastapi_deferred_init-0.2.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8319257248d31c601fefbe34e6ed24e8b2306bdeea9054157fcd36bce87fc949 |
|
MD5 | 8cfd63cd41c1ce9e5a05387165f60d14 |
|
BLAKE2b-256 | f840f67f7b0449b4795a5c21b7039391414d800480d7606323594005ff3a0982 |
Hashes for fastapi_deferred_init-0.2.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fa6f94d1cb8fd8b3a077cc856bf26ee9f1f6dd48054c2cecd9164f5bf2b32613 |
|
MD5 | 26e753c48ce1a2e24cfae6331d19a6e6 |
|
BLAKE2b-256 | 5bca59f8c72b41a225087019ea95b42f06def3d09ec2ba2083072f4676102ab8 |