Skip to main content

Faster FastAPI start-up time for Projects with many nested routers

Project description

fastapi-deferred-init

PyPI - Downloads GitHub license Tests

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastapi_deferred_init-0.2.7.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

fastapi_deferred_init-0.2.7-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

Details for the file fastapi_deferred_init-0.2.7.tar.gz.

File metadata

  • Download URL: fastapi_deferred_init-0.2.7.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.19.2 CPython/3.12.3 Linux/6.8.0-1015-azure

File hashes

Hashes for fastapi_deferred_init-0.2.7.tar.gz
Algorithm Hash digest
SHA256 8f13a7121bfaaed2922db4e11c191f2783b4e557faf257e1f5d4dbcee95cc172
MD5 bf59a7a6936bfb95ddff5e5dd2e0d04d
BLAKE2b-256 52421f660a81e5248cb256b50b8ba69f1424655a8a713d6bd3fba1ea160cc03b

See more details on using hashes here.

File details

Details for the file fastapi_deferred_init-0.2.7-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_deferred_init-0.2.7-py3-none-any.whl
Algorithm Hash digest
SHA256 3060b53cb4473eb3b14d08c17223e32687c664b9c0ebf9e08e47c45c524e4216
MD5 df1e8cc1a6e9416c75fd8eaea99a3755
BLAKE2b-256 34a0be21bb0afd41867060f440f57a5bff14bdf2495ace868ed27f3d8dfe6cef

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page