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
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file inflight_py-1.0.0.tar.gz.
File metadata
- Download URL: inflight_py-1.0.0.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
26cdd9ca9e9ca8659fb9c607ee8a15ba612080c077b9087c58a9f39b91b5c916
|
|
| MD5 |
d4cbac8458e5222b801db06171dd6f4b
|
|
| BLAKE2b-256 |
8006ecba90265e158f23dee0a68d36316d57ed88299344b945caca475387a8b3
|
Provenance
The following attestation bundles were made for inflight_py-1.0.0.tar.gz:
Publisher:
ci.yml on ademmenh/inflight-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
inflight_py-1.0.0.tar.gz -
Subject digest:
26cdd9ca9e9ca8659fb9c607ee8a15ba612080c077b9087c58a9f39b91b5c916 - Sigstore transparency entry: 2618928649
- Sigstore integration time:
-
Permalink:
ademmenh/inflight-py@0be87f2963086b9b78b5b38102640bb3cb5f586d -
Branch / Tag:
refs/heads/main - Owner: https://github.com/ademmenh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@0be87f2963086b9b78b5b38102640bb3cb5f586d -
Trigger Event:
push
-
Statement type:
File details
Details for the file inflight_py-1.0.0-py3-none-any.whl.
File metadata
- Download URL: inflight_py-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3bb1970e6161418da7ca9d36dbc20d4b8372ceb02497c37cd6308fc5f0f555b8
|
|
| MD5 |
43390546b9d394f45a7f79afdd652ea0
|
|
| BLAKE2b-256 |
a7261c8773778db95938422171fe7c80fc6ea6da529f48398e90507e35e9fee2
|
Provenance
The following attestation bundles were made for inflight_py-1.0.0-py3-none-any.whl:
Publisher:
ci.yml on ademmenh/inflight-py
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
inflight_py-1.0.0-py3-none-any.whl -
Subject digest:
3bb1970e6161418da7ca9d36dbc20d4b8372ceb02497c37cd6308fc5f0f555b8 - Sigstore transparency entry: 2618928657
- Sigstore integration time:
-
Permalink:
ademmenh/inflight-py@0be87f2963086b9b78b5b38102640bb3cb5f586d -
Branch / Tag:
refs/heads/main - Owner: https://github.com/ademmenh
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@0be87f2963086b9b78b5b38102640bb3cb5f586d -
Trigger Event:
push
-
Statement type: