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 three primitives: @batch to define the barrier constraints, collect() to suspend the execution and pool data, and scatter() to distribute the results back to the original callers.
import asyncio
from concresce import batch, collect, scatter
@batch(max_window=0.05, max_size=100)
async def fetch_user_score(user_id):
# 1. Execution pauses here.
# Concurrent calls to this function pool their `user_id`s together.
batch_ids = await collect(user_id)
# 2. Only ONE execution path (the leader) resumes from this point.
# The others remain safely suspended in the event loop.
print(f"Making 1 network call for {len(batch_ids)} users...")
bulk_results = await db.bulk_fetch_scores(batch_ids)
# 3. The leader distributes the results back to the suspended followers.
# Every caller gets their specific integer back.
return scatter(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
- Dual-Trigger Barrier: The suspension breaks when either
max_sizeis reached (volumetric) ormax_windowexpires (temporal). High throughput processes instantly; low throughput falls back to the maximum allowed latency. - Keyed Routing: If your bulk API returns data out-of-order or drops missing items, you can pass a dictionary to
scatter({id: result}). It will automatically route the correct result back to the specific caller based on their original input. - Fault Propagation: If the leader crashes during the heavy processing phase, the exception is safely replicated to all suspended followers. Nobody hangs, and the stack unwinds naturally.
- Contextual Safety: If the leader attempts to return without calling
scatter(),concrescedetects the structural failure and safely aborts the followers with aRuntimeErrorrather than leaving them deadlocked.
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-0.1.0.tar.gz.
File metadata
- Download URL: concresce-0.1.0.tar.gz
- Upload date:
- Size: 3.6 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 |
3f3fbe3216fd534ea0505e13c3d7672413e8c23035976f2302aa787eabb32146
|
|
| MD5 |
ffd14a61c7d76ca6e5f086acf05e90a2
|
|
| BLAKE2b-256 |
0b7598a8fa7ba3e57ab3afc70b59323f6983928b8a17d95c2f311acc191fabab
|
File details
Details for the file concresce-0.1.0-py3-none-any.whl.
File metadata
- Download URL: concresce-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.5 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 |
11394f3a671426a3e3946ab56e0518fcaafbb5b1e7da1b12d2d2e2af6223effd
|
|
| MD5 |
2f833dab68bd72ab337c130705332ca2
|
|
| BLAKE2b-256 |
a58bcc150b1a82465edc2e14ff21029859544e52861430658befdcea2591d458
|