Reliable, async batch execution of LLM requests across providers.
Project description
openapi-batch
openapi-batch is a small Python library for running batches of LLM requests reliably.
It provides:
- Async submission by default (you don’t block while the batch runs)
- Durable state in SQLite (track progress, resume inspection)
- Retries + partial failure handling
- Native batch support where providers offer it (OpenAI, Gemini)
- Provider adapters (no gateway required)
- Callbacks for progress, per-item completion, and job completion
Install
pip install openapi-batch
Provider extras:
pip install openapi-batch[openai]
pip install openapi-batch[gemini]
pip install openapi-batch[openai,gemini]
Quick start
Async batch with callbacks (recommended)
from openapi.batch import BatchClient
def on_progress(job, p):
# p is store.Progress for emulated jobs, NativeProgress for native polling
print("progress:", p)
def on_item(job, item_id, result):
print("item:", item_id, result)
def on_complete(job):
print("done:", job.status())
client = BatchClient(
provider="openai",
api_key="...",
default_model="gpt-4o-mini",
)
job = client.map(
mode="native", # native | emulated | auto
items=[
{"item_id": "a", "input": {"prompt": "Return OK"}},
{"item_id": "b", "input": {"prompt": "Return YES"}},
],
on_progress=on_progress,
on_item=on_item,
on_complete=on_complete,
)
print("submitted:", job.job_id)
The call returns immediately. Processing happens in the background.
Run callbacks in a thread pool
If your callbacks do I/O (write to DB, publish to queue, HTTP calls), run them in a thread pool:
job = client.map(
items=items,
on_progress=on_progress,
on_item=on_item,
on_complete=on_complete,
callback_executor="thread",
callback_workers=8,
)
Blocking mode (useful for scripts/tests)
job = client.map(items=items, async_submit=False)
job.wait()
results = job.results_dict()
print(results)
Concepts
Job
A batch execution with a stable job_id. Stored in SQLite.
job.status()
job.progress()
job.info()
Item
One request in the batch, identified by item_id. If you don’t provide it, a deterministic ID is generated.
Result mapping
Results are returned as a dict keyed by item_id.
results = job.results_dict()
ok = results["a"] # ResultOk
err = results["b"] # ResultErr
Modes
- emulated: concurrency-controlled requests (works for any provider adapter)
- native: provider batch APIs (OpenAI, Gemini)
- auto: uses native if available, otherwise emulated
Logging
Enable lightweight progress logs:
export OPENAPI_BATCH_LOG=1
Providers
Currently included:
- OpenAI
- Gemini
- local_echo (tests)
No gateway required — pass the provider to BatchClient.
Testing
Unit tests:
pytest
Integration tests (real APIs, opt-in, may incur cost):
export OPENAI_API_KEY=...
export GEMINI_API_KEY=...
pytest -m integration
What this library does not try to do
- Prompt abstraction
- Workflow orchestration
- Hiding provider semantics
It focuses only on batch execution, durability, and developer experience.
License
MIT
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 openapi_batch-0.1.2.tar.gz.
File metadata
- Download URL: openapi_batch-0.1.2.tar.gz
- Upload date:
- Size: 24.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d6b23cf26ae8c4edb9ab72daac7e6c7af72eb3ddb80a8258c8ed44843f3ccde1
|
|
| MD5 |
273659dd77353f7dbbc721a8f15edbac
|
|
| BLAKE2b-256 |
6ba2512102e9b98d907c38e83714f0b7cb4c13516693b1b4cb9f128445414ddc
|
Provenance
The following attestation bundles were made for openapi_batch-0.1.2.tar.gz:
Publisher:
publish-manual.yml on sireto/openapi-batch
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openapi_batch-0.1.2.tar.gz -
Subject digest:
d6b23cf26ae8c4edb9ab72daac7e6c7af72eb3ddb80a8258c8ed44843f3ccde1 - Sigstore transparency entry: 780375747
- Sigstore integration time:
-
Permalink:
sireto/openapi-batch@4e394b3ceccc5e60ff5d96c7d7b03d625d625f8a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/sireto
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-manual.yml@4e394b3ceccc5e60ff5d96c7d7b03d625d625f8a -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file openapi_batch-0.1.2-py3-none-any.whl.
File metadata
- Download URL: openapi_batch-0.1.2-py3-none-any.whl
- Upload date:
- Size: 31.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2f4295892e213d7016f43e8368dc177be527263596526d7a8670b187ac268f75
|
|
| MD5 |
4fb88c5d8d140b43bfe03b730f45dbc6
|
|
| BLAKE2b-256 |
a709b818903f0247d9b771172d326d03d3dfc352df6cc753e745752ef04e93aa
|
Provenance
The following attestation bundles were made for openapi_batch-0.1.2-py3-none-any.whl:
Publisher:
publish-manual.yml on sireto/openapi-batch
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
openapi_batch-0.1.2-py3-none-any.whl -
Subject digest:
2f4295892e213d7016f43e8368dc177be527263596526d7a8670b187ac268f75 - Sigstore transparency entry: 780375757
- Sigstore integration time:
-
Permalink:
sireto/openapi-batch@4e394b3ceccc5e60ff5d96c7d7b03d625d625f8a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/sireto
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-manual.yml@4e394b3ceccc5e60ff5d96c7d7b03d625d625f8a -
Trigger Event:
workflow_dispatch
-
Statement type: