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.12.tar.gz (8.5 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.12-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: fastapi_deferred_init-0.2.12.tar.gz
  • Upload date:
  • Size: 8.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: pdm/2.26.6 CPython/3.10.19 Linux/6.14.0-1017-azure

File hashes

Hashes for fastapi_deferred_init-0.2.12.tar.gz
Algorithm Hash digest
SHA256 3305c6576eb6265b16fdc1a4f75c8991c33fc42c870fd151a09b26378d233922
MD5 a9f1d95206c167ee8313bd0ec0826290
BLAKE2b-256 e26155a4e9550d82d4a14fd79a6e1df14a4f30a4676b156c3468f3dac443972b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for fastapi_deferred_init-0.2.12-py3-none-any.whl
Algorithm Hash digest
SHA256 cae0492ed841118dadf7ff6afc279891c4f3dcbd629eb40019833201a3144523
MD5 b7481b014830f12d8e86790565639513
BLAKE2b-256 8927f5c7fc212f364712a9bcda73848ac490437225da1661d4aa692fd6ae8db8

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