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.10.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastapi_deferred_init-0.2.10.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.26.6 CPython/3.10.19 Linux/6.11.0-1018-azure

File hashes

Hashes for fastapi_deferred_init-0.2.10.tar.gz
Algorithm Hash digest
SHA256 2e7e40c509bc31318d55df226e39d724999227c51ea29e1b5636e488bdb306ec
MD5 de2d8447cd1ddbe658fa8446c07c5b93
BLAKE2b-256 5e9c4e0db4e547920020ba168f119635eb7ea7a468d3fdb6a6025abe1929fc51

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastapi_deferred_init-0.2.10-py3-none-any.whl
Algorithm Hash digest
SHA256 0d7d287a08c7b03e4593e193805bdea59b927399d03ba9edc0485e0516196f32
MD5 db08babd128109affa9b8d6e08c3cfb3
BLAKE2b-256 345ab2f0eed1335accab4588d861f17e333851c77c4a4f1276455ba237d97264

See more details on using hashes here.

Supported by

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