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.11.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.11-py3-none-any.whl (5.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastapi_deferred_init-0.2.11.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.11.tar.gz
Algorithm Hash digest
SHA256 83f5019fd0fb5971a8c521b7bae9c85ae8b194fe413d280f3ad6792e74051751
MD5 d9d5b90a258cf4f200b83a28ff01d0bb
BLAKE2b-256 9bdffdb2950dd83a4c7162bb87071a03f80a665672185d9e167d75832b4a224a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastapi_deferred_init-0.2.11-py3-none-any.whl
Algorithm Hash digest
SHA256 d8fdefb6448ea77db543dfece63748616d666a86484355afeb19b66b2ba740c1
MD5 f758005bcaf3babe58fd7cabb3ec4710
BLAKE2b-256 6b09f1d6158a7949694a2693637209f650b48c21b152a279540ea12825cc4d38

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