Transparent temporal coalescing and inline micro-batching for Python.
Project description
concresce 💧
Transparent temporal coalescing and inline micro-batching.
Standard solutions to N+1 database or network bottlenecks require spinning up external message queues, background workers, or complex task graphs. concresce solves this dynamically. You write the function as if it processes a single item, and the runtime transparently merges concurrent calls into a single batch in the background.
uv add concresce
The Difference
| Concept | Standard Async Loop | Message Queues (Celery/Kafka) | concresce |
|---|---|---|---|
| Network Footprint | N requests for N items. | 1 request for N items. | 1 request for N items. |
| Architectural Overhead | None. | High (Requires external broker). | None (Pure inline code). |
| Return Routing | Native variables. | Complex (Webhooks / Polling). | Native variables (Futures resolve). |
Usage
You need exactly two primitives: @batch to define the barrier constraint, and collect() to suspend the execution and pool data.
There is zero configuration. The batch window is dynamically defined by the event loop's microtask queue. The routing is handled natively by your return types.
import asyncio
from concresce import batch, collect
@batch
async def fetch_user_score(user_id):
# 1. Execution pauses here.
# Concurrent calls inside the current event loop tick pool their `user_id`s.
batch_ids = await collect(user_id)
# 2. Only ONE execution path (the leader) resumes from this point.
# The others remain safely suspended via Exception-driven control flow.
print(f"Making 1 network call for {len(batch_ids)} users...")
bulk_results = await db.bulk_fetch_scores(batch_ids)
# 3. The leader returns the raw bulk list or dictionary.
# The decorator natively maps and distributes the results back to the followers.
return bulk_results
async def main():
# Fire off 5 requests simultaneously
results = await asyncio.gather(
fetch_user_score(1),
fetch_user_score(2),
fetch_user_score(3),
fetch_user_score(4),
fetch_user_score(5)
)
# Returns:[100, 250, 190, 300, 120]
print(results)
asyncio.run(main())
Core Mechanics
- Event Loop Batching: There are no arbitrary
max_sizeormax_windowtimers to tune.concresceyields exactly once (await asyncio.sleep(0)) to the event loop. Under heavy load, batches are massive. Under low load, batches execute instantly. The tuning emerges purely from the traffic itself. - Native Type Routing: The leader does not need to call a special scatter function. If your database returns a
list, the system unzips it by index. If it returns out-of-order or missing data, just return a dictionary ({id: result}) andconcrescehandles exact key-based routing automatically. - Fault Propagation: If the leader crashes during the heavy processing phase, the exception is intercepted and safely replicated to all suspended followers. Nobody hangs, and the stack unwinds naturally.
Project details
Release history Release notifications | RSS feed
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 concresce-1.0.0.tar.gz.
File metadata
- Download URL: concresce-1.0.0.tar.gz
- Upload date:
- Size: 3.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CachyOS Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8816a744e4c6ac326124dc3c5c7f5af8a2c8430d8f7a2b08c6e166fe7127397a
|
|
| MD5 |
9af610025364cc8d958ce9842829534e
|
|
| BLAKE2b-256 |
ab9992a99bc764bec00a6c8321b9a52f46ec80f23d107cf5eb63367c7ebcf55d
|
File details
Details for the file concresce-1.0.0-py3-none-any.whl.
File metadata
- Download URL: concresce-1.0.0-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.3 {"installer":{"name":"uv","version":"0.11.3","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"CachyOS Linux","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5e3a2650f39204462969251e7266dcf7980b41912b4c513fdc6be2673508b42c
|
|
| MD5 |
7f81da7378aadaafd15dc0f0d4fe6bac
|
|
| BLAKE2b-256 |
cc093a0d20b52265c760ff5f90437bfad90fcc418afd78ae64184777e481a3e6
|