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.6.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | f10d6e4bbf6655af979da6db3944f5da21529d9864ac3d8e84cea7d1e1c262ca |
|
MD5 | 63ffebaf293cda1caf003f78bc15d392 |
|
BLAKE2b-256 | 1f752e18a25405d7d786ae541eea43995e1adb44f6d0bf2771f4066682aed31d |
Hashes for fastapi_deferred_init-0.2.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 522969e127f22e23ba7256dc2ed07027de49192759290376fbdc354f89956569 |
|
MD5 | d6b97814dfec705211f404bbc18f3a2a |
|
BLAKE2b-256 | 7e92df2aa95374059015455db98f470c0e50405b27f0423a83f6e6261243b866 |