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.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 406183d5680b0d7866e18df31eb33ec2e289f2c184cca119a5ed290ccad5ac69 |
|
MD5 | 3f3e3ecab2508ab4e48fa5388ea29ccb |
|
BLAKE2b-256 | 39d4a03077be05b0ebb6a0858edd1700bb1cebeea6297a88765fff9c5743969b |
Hashes for fastapi_deferred_init-0.2.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04354a03971f1de0738a81e7def70334022548b5b59a41096f83c6a684ccad93 |
|
MD5 | 4467437f7b6595821aa9aeea4f8671c1 |
|
BLAKE2b-256 | 93c70a0b53a69f70342f7f08edbddbe57c09dedb7cb9780bbf845e92d6cbc03b |