Batch processing library for Claude API. Handles concurrent requests with automatic retry logic, rate limiting and progress tracking.
pip install -r requirements.txtfrom claudebatch import BatchProcessor
processor = BatchProcessor(api_key="your-key")
prompts = [
"Summarize this article...",
"Translate to French...",
"Extract key points..."
]
results = processor.run(prompts)
for result in results:
print(result.content)- Concurrent request processing with configurable parallelism
- Exponential backoff retry on rate limits and errors
- Progress tracking with callbacks
- Result aggregation and error handling
- Token usage tracking
processor = BatchProcessor(
api_key: str,
model: str = "claude-3-sonnet-20240229",
max_concurrent: int = 5,
max_retries: int = 3,
timeout: int = 60
)run(prompts: List[str]) -> List[Response]- Process batch of promptsrun_async(prompts: List[str]) -> List[Response]- Async versionset_progress_callback(fn: Callable)- Set progress callback
# Environment variables
ANTHROPIC_API_KEY=your-key
CLAUDE_BATCH_MAX_CONCURRENT=10
CLAUDE_BATCH_TIMEOUT=120def on_progress(completed, total):
print(f"Progress: {completed}/{total}")
processor = BatchProcessor(api_key=key)
processor.set_progress_callback(on_progress)
results = processor.run(prompts)results = processor.run(prompts)
for i, result in enumerate(results):
if result.error:
print(f"Prompt {i} failed: {result.error}")
else:
print(result.content)MIT