Catalog PyPI
PACKAGE EXPLORERView in registry

aiocoalesce

PyPI

A best-in-class async request coalescing library for Python.

Versions collected1
Direct dependencies2From release 0.1.0
Last observed21 Oct, 11:44 UTC

README

Version 0.1.0 documentation

aiocoalesce

A best-in-class async request coalescing library for Python (3.9+).

aiocoalesce ensures that multiple concurrent async requests for the same key share a single execution (the "SingleFlight" pattern). This protects your backend from Thundering Herds without the complexity of Redis or caching layers.

Key Difference: Unlike other libraries, aiocoalesce is Cancellation Safe. If the first user disconnects, the shared work continues for other waiting users.

Installation

pip install aiocoalesce

Usage

import asyncio
from aiocoalesce import Coalescer

# Create a global coalescer
coalescer = Coalescer()

async def get_user_data(user_id: int):
    # Simulate DB call
    await asyncio.sleep(1)
    return {"id": user_id, "name": "Alice"}

# In your API handler:
async def handler(user_id):
    # If 10 requests come in at once for user_id=1, 
    # 'get_user_data' runs ONLY ONCE.
    return await coalescer.run(user_id, get_user_data(user_id))

Why aiocoalesce?

FeatureaiocoalesceExisting singleflightasyncio.Lock
PatternTrue CoalescingTrue CoalescingSequential Locking
Cancellation✅ Shielded (Safe)❌ Cascading Fails✅ Safe
Exec ModelConcurrentConcurrentSequential (Slow)

Use Case

Perfect for:

  • FastAPI endpoints with expensive DB queries.
  • ML Inference servers (prevent running same model input twice).
  • Proxy servers to reduce upstream load.

License

MIT

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 1

Collected releases
VersionPublishedDirect dependenciesOpen version
0.1.018 Dec 20252

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Metadata history

Meaningful changes
Current collected state Current

Observed since 21 Oct, 11:44 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:64904527e8643a57199ed4771d661280c29f669e1f9a02158ad561bef9162a3e