Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openapi_batch-0.1.1.tar.gz (23.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

openapi_batch-0.1.1-py3-none-any.whl (29.4 kB view details)

Uploaded Python 3

File details

Details for the file openapi_batch-0.1.1.tar.gz.

File metadata

  • Download URL: openapi_batch-0.1.1.tar.gz
  • Upload date:
  • Size: 23.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for openapi_batch-0.1.1.tar.gz
Algorithm Hash digest
SHA256 e21f46cf6bc1f187f7d0a5a00e8e4e12e670ddd01597e52760c1d994bc633519
MD5 9f9e53ff0af67145f4df284250487865
BLAKE2b-256 d66cd19fe8903c3519e63708c197365ff603f1ea6086acbe16348e14b6121f3b

See more details on using hashes here.

Provenance

The following attestation bundles were made for openapi_batch-0.1.1.tar.gz:

Publisher: publish-manual.yml on sireto/openapi-batch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file openapi_batch-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: openapi_batch-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 29.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for openapi_batch-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0c4bd71e83739011bf50287cc07143da2759622cbd354cf38258f46c06b97f37
MD5 d31db3fdbc38e689d6fb389f487dd19e
BLAKE2b-256 1c1bcdcf917fd6d91ac69e5fa585da06a30aebd6fe650466977c2a694acbba3c

See more details on using hashes here.

Provenance

The following attestation bundles were made for openapi_batch-0.1.1-py3-none-any.whl:

Publisher: publish-manual.yml on sireto/openapi-batch

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page