FastAPI Overflow
When using FastAPI with a synchronous SQLAlchemy session dependency, per the official example https://fastapi.tiangolo.com/tutorial/sql-databases/, high loads can lead to temporary deadlocks, timeouts and poor performance.
This is a known issue, for which a PR is open. This library exists to allow users to easily patch the issue and run their code in the mean time.
We provide a single function to patch fastapi: fastapi_overflow.patch() should be called before starting your app in order to patch FastAPI's thread handling.
Usage
Use it like this:
import fastapi_overflow
from fastapi import FastAPI
fastapi_overflow.patch() # run this before starting your app
app = FastAPI()
Changing the default thread limit
You can increase the number of threads from the default (40) using the fastapi_overflow.set_thread_limit function.
With a very high number of threads you might also want to increase the reserve used to prevent deadlocks from its
default of 5. You will need to add this to your startup events, or lifetime function:
import fastapi_overflow
from fastapi import FastAPI
from contextlib import asynccontextmanager
fastapi_overflow.patch() # run this before starting your app
@asynccontextmanager
async def lifespan(app: FastAPI):
fastapi_overflow.set_thread_limit(default_limit=80, reserve_limit=10)
... # any other setup here
yield
... # any other teardown here
app = FastAPI(lifespan=lifespan)
Some experimentation is needed to find the best numbers for your workload.
Metadata
Release files for fastapi-overflow 0.1.7
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| fastapi_overflow-0.1.7.tar.gz | 4.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| fastapi_overflow-0.1.7-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.3 kB
Release files / fastapi_overflow-0.1.7.tar.gz
| Download URL | fastapi_overflow-0.1.7.tar.gz |
|---|---|
| Size | 4.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7beb4cc928edfda82c053df860b980e92de472c9a55e1795cd8de8478cac52fe
|
|
BLAKE2b-256 checksum How to use checksums |
b814b5801c737cfcb167037cc3317a222a19603a50bdd5a2a4c761b5fd411ec8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 29, 2026.
Transparency logRelease files / fastapi_overflow-0.1.7-py3-none-any.whl
| Download URL | fastapi_overflow-0.1.7-py3-none-any.whl |
|---|---|
| Size | 4.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a933f3a0eedd77f30ecd4365eaa711fad4f5118d31a92e14cbb666eae119cb2d
|
|
BLAKE2b-256 checksum How to use checksums |
b1d45a51b82da8dc5e64721d430ccd562bcdd11749992e460d9b1a3f0c755d4b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 29, 2026.
Transparency log