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.5.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 21292d76afe2b3e4a5c1f0671a500f375f8acbcffccda75626f1726707083da6 |
|
MD5 | 2a22207efc3ad77977e0b4a3b5902713 |
|
BLAKE2b-256 | 7097e1563d09f7c9f4b9acfec89b9e82322e673a4a82b0373474fbbabbdf3464 |
Hashes for fastapi_deferred_init-0.2.5-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | de7b890ef620c39f98b691d11d67a72d65f61142c4bf3afbf510f92b0fa3c633 |
|
MD5 | c5a344428831c03f805894d85ec796d7 |
|
BLAKE2b-256 | 4a52e3fd58cec1935ef94b021a8438181ada48ca1173256b02ec26a96e8068bc |