Batchman
A flexible Python library for managing batches of requests to LLM inference providers.
Features
- Use batch providers through a unified API [supported providers:
OpenAI,Anthropic,Exxa] - Validate requests before uploading
- Keep track of uploaded batches and their status
Installation
From PyPI
pip install batchman
Quickstart
Creating a batch
import batchman
from batchman import Request, UserMessage
# Initialize a new batch
batch = batchman.create_batch("my batch")
# Example: Generate stories for different professions
jobs = [
"an astronaut", "a doctor", "a firefighter", "a teacher",
"a chef", "a farmer", "a pilot", "a scientist"
]
# Add requests to the batch
batch.add_requests([
Request([UserMessage(f"Write a short story about a child dreaming of being {job}.")])
for job in jobs]
)
# Configure batch parameters
batch.override_request_params(
system_prompt=(
"You are a creative writer who writes short stories for children. "
"The goal of the stories are to motivate them to pursue their dreams "
),
model="llama-3.1-70b-instruct-fp16",
temperature=0.5,
)
# Set the provider (uses EXXA_API_KEY environment variable by default)
batch.set_provider(provider="exxa")
# Upload the batch
batch.upload()
Managing Batches
The batchman command sync all batches. This will fetch the status of all non-completed batches, and then display
them in an interactive way
batchman
It will display a table with the batches, and you can remove or cancel them.
Advanced Usage
Custom Provider Configuration
If you need to specify the api_key and/or the base_url for a provider, you can do so by passing the provider_config parameter to the create_batch function.
batch = batchman.create_batch(
name="my batch",
provider="exxa",
provider_config=ProviderConfig(
api_key="your-api-key",
url="https://api.example.com",
)
)
Security
Once a provider is configured (at batch creation time or later), the provider configuration including the api_key is
stored in the providers_config.jsonl file, in a .batchman directory in your home directory. This file should not be shared
with others. The batches directory only store hash references to this file, and are safe to share.
For Development
git clone https://github.com/yourusername/batchman.git
cd batchman
uv pip install -e .[dev]
to build the pypi package with uv, run
uv build
to publish to testpypi, run
uv publish --index testpypi --username __token__ --password $PYPITEST_TOKEN
Downloading from the test index:
pip install --verbose -i https://test.pypi.org/simple/ --extra-index-url https://pypi.org/simple/ batchman
Building the documentation
tox -e docs
Contributing
Contributions are welcome! Please see our (TODO) Contributing Guide for details.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for batchman 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| batchman-1.1.0.tar.gz | 29.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| batchman-1.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 61.8 kB
Release files / batchman-1.1.0.tar.gz
| Download URL | batchman-1.1.0.tar.gz |
|---|---|
| Size | 29.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6d530c554e29dbdc775a48bb770c129a346b8aeb5e1d3d081e5dba6ce2c2afb8
|
|
BLAKE2b-256 checksum How to use checksums |
028f319b36b59692257d11eeddb90de812b0cc116ad8d1b32c7d5ed93221a100
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.11
|
Release files / batchman-1.1.0-py3-none-any.whl
| Download URL | batchman-1.1.0-py3-none-any.whl |
|---|---|
| Size | 32.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
245df1aa75d591f57b994fbbbe24c574dd3dfdd2b8109be00e92b508b7c2f4dc
|
|
BLAKE2b-256 checksum How to use checksums |
5ce4a4c31e8a37ae63ed0192b3c28eb3f4a2472f26a2c699bf9705b2e8c8abac
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.11
|