Skip to main content

Tiny wrapper for batched multi-provider LLM calls

Project description

batchcal — a tiny wrapper for multi‑provider batch LLM calls

When you have jobs that don't require a real time responses and can use "save token mode" performance, this library can help with reducing token cost and bypass online rate limits and have separate quotas. eg. nightly jobs, dataset annotation, evals etc.

Features

  • Unified request/response dataclasses
  • Providers: OpenAI
  • Async single + batch with bounded concurrency
  • Simple QPS rate limiting
  • Retries with exponential backoff + jitter on transient errors
  • Per‑request timeouts
  • Optional response validation hook
  • Pluggable transport (httpx by default)

Install pip install batchcal (or clone then: pip install .)

Env Vars

  • OPENAI_API_KEY

Usage

Note: you must pip install httpx (installed automatically if using pyproject) and have valid API keys.

Example:

from batchcal import BatchClient, OpenAIProvider, Msg

async def main():
    client = BatchClient(OpenAIProvider(), qps=2.0, max_concurrency=5)
    resp = await client.acomplete([Msg.user("Ping")], model="gpt-4.1-mini")
    print(resp.content)

With Validation:

from batchcal import BatchClient, OpenAIProvider, Msg, require_json

client = BatchClient(OpenAIProvider(), validate=require_json)

# or custom:
def validate_nonempty(r):
    if not r.content.strip():
        raise ValueError("Empty output")

Batch:

prompts = [[Msg.user(f"Item {i}")] for i in range(20)]
resps = await client.abatch(prompts, model="gpt-4.1-mini")
for r in resps:
    print(r.content)

Testing Install dev deps: pip install .[dev] Run: pytest -q Tests mock the OpenAI API (no network, no real key needed).

Publishing

  1. Update version in pyproject.toml
  2. python -m build
  3. twine upload dist/*

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

batchcal-0.1.0.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

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

batchcal-0.1.0-py3-none-any.whl (8.5 kB view details)

Uploaded Python 3

File details

Details for the file batchcal-0.1.0.tar.gz.

File metadata

  • Download URL: batchcal-0.1.0.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for batchcal-0.1.0.tar.gz
Algorithm Hash digest
SHA256 65a28f594e9b8c3d5b453c5697298efb5e306ed26d6762608f499c5963790e1b
MD5 2a9d84cbe0cbe22cf5ef1d5ca44bdd39
BLAKE2b-256 2baf0fce827276542dd75a24557033dc8a4ad41cba5187d2b12261203067b9b0

See more details on using hashes here.

File details

Details for the file batchcal-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: batchcal-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for batchcal-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 905b8010186418ad530d6ee8945854e14d2d522b2faee60da64335d47c6932a1
MD5 533d7d7f39f2e6ae8ef66ba36989a3f9
BLAKE2b-256 6357e681844685709de084fad6c2cbfe92422305d409f2523bfaa3c021fda969

See more details on using hashes here.

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