Reliable, async batch execution of LLM requests across providers.
Project description
openapi-batch
A small Python library that makes batch LLM requests reliable and easy across providers.
It handles:
- async submission (non-blocking by default)
- retries and partial failures
- durable progress tracking (SQLite)
- provider differences (OpenAI, Gemini, others)
- callbacks when results are ready
You submit items → you get a job handle → results arrive later.
Install
pip install openapi-batch
Optional provider extras:
pip install openapi-batch[openai]
pip install openapi-batch[gemini]
pip install openapi-batch[openai,gemini]
Quick example
Async batch with callback (recommended)
from openapi.batch import BatchClient
def on_done(job):
print("status:", job.status())
print(job.results_dict())
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_complete=on_done,
)
print("submitted:", job.job_id)
Submission returns immediately. Processing happens in the background.
Blocking usage (for scripts/tests)
job = client.map(items=items, async_submit=False)
job.wait()
results = job.results_dict()
Concepts (brief)
Job
A batch execution with a stable job_id.
Stored durably in SQLite.
Item
One logical request. Identified by item_id.
If you don’t provide one, a deterministic ID is generated.
Modes
- emulated – concurrency-controlled requests (works everywhere)
- native – provider batch APIs (OpenAI, Gemini)
- auto – native if available, otherwise emulated
Results
Always mapped back by item_id.
{
"a": ResultOk(...),
"b": ResultErr(...)
}
Partial success is normal and expected.
Providers
Currently supported:
- OpenAI
- Gemini
- Local echo (testing)
Providers are internal adapters. You do not need to build a gateway.
Persistence
Each job is stored in SQLite:
- survives process restarts
- supports retries
- allows progress inspection
job.progress()
job.status()
Logging
Enable lightweight progress logs:
export OPENAPI_BATCH_LOG=1
You’ll see submission, polling, heartbeats, and completion.
Testing
Unit tests (fast)
- local_echo provider
- no network
Integration tests (real APIs)
export OPENAI_API_KEY=...
export GEMINI_API_KEY=...
pytest -m integration
Integration tests are opt-in and may incur cost.
What this library does not try to do
- It does not abstract prompts
- It does not hide provider semantics
- It does not invent new APIs
It focuses only on batch execution, reliability, and DX.
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.0.tar.gz.
File metadata
- Download URL: openapi_batch-0.1.0.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c83787f3b4e56a778865f75e3362648273d6562e35cd9dbcd29a36dd51fa11d9
|
|
| MD5 |
d12694d41cc6912259767ecc215475ad
|
|
| BLAKE2b-256 |
a5ec541707eb3c2986e0b6c3469e33e9ace659189ca39aa751c9c3d1d0047097
|
Provenance
The following attestation bundles were made for openapi_batch-0.1.0.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.0.tar.gz -
Subject digest:
c83787f3b4e56a778865f75e3362648273d6562e35cd9dbcd29a36dd51fa11d9 - Sigstore transparency entry: 780346608
- Sigstore integration time:
-
Permalink:
sireto/openapi-batch@56b89703b3f845b0c48223782260bea03d596938 -
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@56b89703b3f845b0c48223782260bea03d596938 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file openapi_batch-0.1.0-py3-none-any.whl.
File metadata
- Download URL: openapi_batch-0.1.0-py3-none-any.whl
- Upload date:
- Size: 4.5 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 |
6b8dd8a960df4fd92de21dccfe4cb96b833683349b2378ae2f5ce39ebbe72a1d
|
|
| MD5 |
f0fc70f9efd4bcad05304d44ed7c3055
|
|
| BLAKE2b-256 |
ca76a83f164549f00d8ecb2a4c9c05cec06529419a55b47d500e46fd65677ae4
|
Provenance
The following attestation bundles were made for openapi_batch-0.1.0-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.0-py3-none-any.whl -
Subject digest:
6b8dd8a960df4fd92de21dccfe4cb96b833683349b2378ae2f5ce39ebbe72a1d - Sigstore transparency entry: 780346611
- Sigstore integration time:
-
Permalink:
sireto/openapi-batch@56b89703b3f845b0c48223782260bea03d596938 -
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@56b89703b3f845b0c48223782260bea03d596938 -
Trigger Event:
workflow_dispatch
-
Statement type: