inflight
Deduplicate concurrent async requests by query_key. When multiple identical coroutines are in-flight, only one executes — the rest wait for and receive the same result.
Why
In high-concurrency environments, identical queries (same DB row, same cache key) accumulate while each one independently hits the database or cache. inflight collapses these into a single call.
Install
pip install inflight
Usage
import json
from inflight import InFlight
class Repo:
def __init__(self, db, cache):
self.db = db
self.cache = cache
self._inflight = InFlight()
async def get_user(self, user_id: int):
cached = await self._inflight.execute(
f"user:{user_id}:cache",
lambda: self.cache.get(f"user:{user_id}"),
)
if cached:
return json.loads(cached)
result = await self._inflight.execute(
f"user:{user_id}:db",
lambda: self.db.execute(
select(users).where(users.c.id == user_id)
),
)
await self.cache.set(f"user:{user_id}", json.dumps(result), ex=5)
return result
Benchmarks
See benchmarks/README.md for performance comparison with and without inflight.
License
GPL-3.0-only
Metadata
Release files for inflight-py 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| inflight_py-1.0.0.tar.gz | 10.1 kB | With provenance | Details for inflight_py-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| inflight_py-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for inflight_py-1.0.0-py3-none-any.whl |
Total release size: 15.0 kB
Release files / inflight_py-1.0.0.tar.gz
| Download URL | inflight_py-1.0.0.tar.gz |
|---|---|
| Size | 10.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
26cdd9ca9e9ca8659fb9c607ee8a15ba612080c077b9087c58a9f39b91b5c916
|
|
BLAKE2b-256 checksum How to use checksums |
8006ecba90265e158f23dee0a68d36316d57ed88299344b945caca475387a8b3
|
| 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 Aug 27, 2026.
Transparency logRelease files / inflight_py-1.0.0-py3-none-any.whl
| Download URL | inflight_py-1.0.0-py3-none-any.whl |
|---|---|
| Size | 4.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3bb1970e6161418da7ca9d36dbc20d4b8372ceb02497c37cd6308fc5f0f555b8
|
|
BLAKE2b-256 checksum How to use checksums |
a7261c8773778db95938422171fe7c80fc6ea6da529f48398e90507e35e9fee2
|
| 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 Aug 27, 2026.
Transparency logSecurity for inflight-py 1.0.0
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.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for inflight_py-1.0.0.tar.gz
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 Aug 27, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.