Skip to main content

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/*

Metadata

Release files for batchcal 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for batchcal 0.1.0
File Size Uploaded Provenance
batchcal-0.1.0.tar.gz 7.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for batchcal 0.1.0
File Interpreter ABI Platform
batchcal-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 16.0 kB

Release files / batchcal-0.1.0.tar.gz

Download URL batchcal-0.1.0.tar.gz
Size 7.5 kB
Tags Source
SHA-256 checksum
How to use checksums
65a28f594e9b8c3d5b453c5697298efb5e306ed26d6762608f499c5963790e1b
BLAKE2b-256 checksum
How to use checksums
2baf0fce827276542dd75a24557033dc8a4ad41cba5187d2b12261203067b9b0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.8

Release files / batchcal-0.1.0-py3-none-any.whl

Download URL batchcal-0.1.0-py3-none-any.whl
Size 8.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
905b8010186418ad530d6ee8945854e14d2d522b2faee60da64335d47c6932a1
BLAKE2b-256 checksum
How to use checksums
6357e681844685709de084fad6c2cbfe92422305d409f2523bfaa3c021fda969
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.8

Security for batchcal 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page