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.0.tar.gz (4.6 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.0-py3-none-any.whl (4.5 kB view details)

Uploaded Python 3

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

Hashes for openapi_batch-0.1.0.tar.gz
Algorithm Hash digest
SHA256 c83787f3b4e56a778865f75e3362648273d6562e35cd9dbcd29a36dd51fa11d9
MD5 d12694d41cc6912259767ecc215475ad
BLAKE2b-256 a5ec541707eb3c2986e0b6c3469e33e9ace659189ca39aa751c9c3d1d0047097

See more details on using hashes here.

Provenance

The following attestation bundles were made for openapi_batch-0.1.0.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.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

Hashes for openapi_batch-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6b8dd8a960df4fd92de21dccfe4cb96b833683349b2378ae2f5ce39ebbe72a1d
MD5 f0fc70f9efd4bcad05304d44ed7c3055
BLAKE2b-256 ca76a83f164549f00d8ecb2a4c9c05cec06529419a55b47d500e46fd65677ae4

See more details on using hashes here.

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

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