Skip to main content

A simple Python wrapper for OpenAI Batch workflows.

Project description

batchkit

batchkit is a thin Python wrapper around the OpenAI Batch API.

Install from PyPI:

pip install batchkit-ai

Import as:

import batchkit

It is designed to remove the repetitive parts of batch usage:

  • building JSONL request files
  • uploading files and creating batches
  • polling batch status
  • downloading output and error artifacts
  • reconciling results back to the original inputs
  • retrying failed rows

Goals

  • keep the official openai SDK under the hood
  • make the happy path one normal Python flow
  • persist inspectable local manifests under .batchkit/
  • support both sync and async usage

Example

from openai import OpenAI
from batchkit import BatchClient


sdk = OpenAI()
client = BatchClient(sdk)

job = client.map(
    name="movie-classification",
    items=movies,
    model="gpt-4.1-mini",
    build_request=lambda movie: {
        "input": movie["overview"],
    },
)

results = job.wait(progress=True)

for row in results.rows:
    if row.ok:
        print(row.custom_id, row.response)
    else:
        print(row.custom_id, row.error)

Development

This project is built test-first.

uv venv --python 3.11
uv pip install -e ".[dev]"
.venv/bin/python -m pytest

Release

Publishing is handled by GitHub Actions.

  • create a version tag like v0.1.0
  • push the tag
  • approve the pypi environment job
  • the Publish workflow uploads batchkit-ai to PyPI

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

batchkit_ai-0.1.0.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

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

batchkit_ai-0.1.0-py3-none-any.whl (20.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for batchkit_ai-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e160853fc7e6b9006b7e34d1ab571580c7cc22689642850a7242ba92dee08f0e
MD5 e2847611074ed46f3eeee16a6cbd9214
BLAKE2b-256 30e87ff7256c83413086e7fd08474dd0866325b32d929fef92d030d6b87d436b

See more details on using hashes here.

Provenance

The following attestation bundles were made for batchkit_ai-0.1.0.tar.gz:

Publisher: publish.yml on thesaadfarooq/batchkit

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

File details

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

File metadata

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

File hashes

Hashes for batchkit_ai-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aef8bc9ea1a1483e22c0f88d17b925cd38795ce668e8651f764e4b1b6e176d00
MD5 fa6e8faa97bc8d6dc66135a81288f381
BLAKE2b-256 0effb482fac412503c5f249acbde289c3be6d85b53e2b318aa4884e5baa8daea

See more details on using hashes here.

Provenance

The following attestation bundles were made for batchkit_ai-0.1.0-py3-none-any.whl:

Publisher: publish.yml on thesaadfarooq/batchkit

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