AsyncBatcher
AsyncBatcher combines concurrent Python requests into batches and routes each result back to its caller.
Wrap an existing bulk function, subclass AsyncBatcher, or use an adapter for a supported database,
messaging client, or prediction model. The core package has no runtime dependencies.
Start with your workload
| You need to… | Start here |
|---|---|
| Combine concurrent web requests into model predictions or writes | Function quickstart, then the FastAPI lifespan recipe |
| Import a large file or consume an async stream without keeping all results | Bounded maps, SQLite imports, and recovery choices |
| Use an existing database, messaging, or prediction client | Choose its adapter and read its failure/ownership rules |
| Send embeddings to a vector store | Two-stage pipeline and Pinecone |
| Keep tenants, model revisions, or backend destinations separate | Compatible request groups and the workload guide |
| Limit bytes, tokens, or estimated work as well as request count | Cost budgets |
Start with a bounded importer or interactive service. The workload guide helps choose limits, preserve routing metadata, and decide whether batching fits your backend. Batching requires a useful bulk operation; it is not a rate limiter, durable queue, or exactly-once delivery system.
Install
Python 3.11 or newer is required. This README targets Async Batcher 0.3.0; check the release history for publication status. Install the package into your application's environment:
python -m pip install 'async-batcher==0.3.0'
The core has no runtime dependencies. Add only the extras you need, for example:
python -m pip install 'async-batcher[aws]==0.3.0'
See installation for uv, other extras, and repository recipes,
and migration from 0.2.2 before upgrading. Core and adapter usage
does not need a source checkout. Runnable files under examples/ are repository
recipes, with separate setup instructions.
Quickstart
Save this as demo.py and run python demo.py in the environment where you installed the package:
import asyncio
from async_batcher import AsyncBatcher
async def double_many(values: list[int]) -> list[int]:
return [value * 2 for value in values]
async def main():
async with AsyncBatcher.from_callable(
double_many, max_batch_size=5, max_queue_size=20, max_queue_time=0.01, concurrency=2
) as batcher:
results = await asyncio.gather(*(batcher.process(i) for i in range(10)))
print(results) # [0, 2, 4, 6, 8, 10, 12, 14, 16, 18]
asyncio.run(main())
process() is a coroutine: submit calls concurrently to form batches. A loop that awaits each
call before submitting the next normally produces single-item batches. Processing starts
automatically. Stop the batcher before closing its clients, model resources, or executor.
Existing subclasses and adapters support the same managed lifecycle.
Guides
- Compatibility and migration: published features, Python requirements, and upgrade checks.
- Bounded starting configurations: copyable importer and interactive service examples.
- Choose by workload: request compatibility, safe metadata, and configuration ownership.
- Batch an existing function: callable processors and managed cleanup.
- Bulk and streaming producers: bounded maps and waiting for queue space.
- Cost budgets: byte, token, or work limits alongside batch counts.
- Variable-length inference: padding, conservative token budgets, and per-request output shapes.
- Operational visibility: snapshots and payload-free completion events.
- Grouped batching: isolate compatible requests with bounded child ownership.
- In-flight coalescing: share equivalent concurrent requests with bounded ownership.
- Cookbook: runnable SQLite imports, embedding pipelines, and measured batch sizes.
- Resumable imports: immutable JSONL input with atomic SQLite checkpoints.
- Rejected-record imports: continue past known input errors and retain a metadata-only audit.
- Durable embedding handoff: save vectors before delivery and replay unfinished upserts.
- Provider quota and retry policy: shared pacing, finite throttling retries, and cancellation.
- Cohere to Pinecone: real embeddings into an existing compatible vector index.
- FastAPI recipe: lifespan-managed predictions, SQLite writes, and HTTP overload handling.
- Operational recipes: separate deadlines, shared backend capacity, thread lifetime, and bounded telemetry.
- Core API and lifecycle: limits, result mapping, errors, shutdown, restart, and executors.
- Contributing: locked development environments, test selection, integration services, and CI.
- Benchmarks: reproducible core measurements and archived application results.
- Public type contracts: inferred results, typed options, and installed-package checks.
- Security reporting and Code of Conduct.
Optional adapters
The eight extras are independent; importing async_batcher does not import their clients.
All adapters use the core lifecycle, with the limits and resource ownership described in each guide.
| Extra | Operations | Guide |
|---|---|---|
aws |
DynamoDB reads/writes; Kinesis and Firehose records | DynamoDB, AWS streams |
sqlalchemy |
SQLAlchemy inserts and ORM updates | SQLAlchemy |
scylla |
cqlengine insert/update/delete batches | ScyllaDB |
mongodb |
Ordered native PyMongo writes | MongoDB |
kafka |
Native aiokafka producer batches | Kafka |
pinecone |
Vector upsert/fetch/delete | Pinecone |
keras |
Dense-input Keras inference | Keras |
sklearn |
Dense or sparse scikit-learn inference | scikit-learn |
Services that do not offer a suitable bulk operation need a custom process_batch implementation.
Batching alone does not enforce a service's request-rate limit or guarantee exactly-once side effects.
Metadata
Release files for async-batcher 0.3.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 |
|---|---|---|---|---|
| async_batcher-0.3.0.tar.gz | 45.5 kB | With provenance | Details for async_batcher-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| async_batcher-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for async_batcher-0.3.0-py3-none-any.whl |
Total release size: 102.4 kB
Release files / async_batcher-0.3.0.tar.gz
| Download URL | async_batcher-0.3.0.tar.gz |
|---|---|
| Size | 45.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
272fd51094013f29fc73e8dcfebacc301c3a3dc0125e3daf98cc5108b1ca6f56
|
|
BLAKE2b-256 checksum How to use checksums |
e48f7db09f50fe90870bd7de884ab4edd2352f7516ad99bf7d2471ab36387a84
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 8, 2026.
Transparency logRelease files / async_batcher-0.3.0-py3-none-any.whl
| Download URL | async_batcher-0.3.0-py3-none-any.whl |
|---|---|
| Size | 56.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6335121c7535a43689cf7158d34e4f5dec2573edbe5f38b378cc01b8c946c6c7
|
|
BLAKE2b-256 checksum How to use checksums |
cbbd3ca62da63102fb7f6b6968659a5799f97a5818bb600dd7e0994bf8290f77
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 8, 2026.
Transparency logSecurity for async-batcher 0.3.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 async_batcher-0.3.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 Nov 8, 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.