Skip to main content

A package for batch processing with sync and async capabilities

Project description

batch_please

A flexible and efficient Python library for processing large datasets in batches, with support for both synchronous and asynchronous operations.

Features

  • Process large datasets in customizable batch sizes
  • Support for both synchronous and asynchronous processing
  • Flexible input handling - accepts iterables or dictionaries of keyword arguments
  • Checkpoint functionality to resume processing from where it left off
  • Optional progress bar using tqdm
  • Configurable concurrency limit for asynchronous processing
  • Logging support

Installation

pip install batch_please  

Quick Start

Synchronous Processing

from batch_please import BatchProcessor

# Simple iterable input
def process_func(item):
    return f"Processed: {item}"

processor = BatchProcessor(
    process_func=process_func,
    batch_size=100,
    use_tqdm=True
)

input_data = range(1000)
processed_items = processor.process_items_in_batches(input_data)

# Dictionary input with keyword arguments
def process_with_params(name, value):
    return f"{name}: {value}"

processor = BatchProcessor(
    process_func=process_with_params,
    batch_size=100,
    use_tqdm=True
)

input_data_dict = {
    f"item_{i}": {"name": f"Item {i}", "value": i * 10} 
    for i in range(100)
}
processed_items = processor.process_items_in_batches(input_data_dict)

Asynchronous Processing

import asyncio
from batch_please import AsyncBatchProcessor

# Simple iterable input
async def async_process_func(item):
    await asyncio.sleep(0.1)
    return f"Processed: {item}"

async def main():
    processor = AsyncBatchProcessor(
        process_func=async_process_func,
        batch_size=100,
        max_concurrent=10,
        use_tqdm=True
    )

    input_data = range(1000)
    processed_items = await processor.process_items_in_batches(input_data)
    
    # Dictionary input with keyword arguments
    async def process_with_params(name, value):
        await asyncio.sleep(0.1)
        return f"{name}: {value}"
    
    processor = AsyncBatchProcessor(
        process_func=process_with_params,
        batch_size=100,
        max_concurrent=10,
        use_tqdm=True
    )
    
    input_data_dict = {
        f"item_{i}": {"name": f"Item {i}", "value": i * 10} 
        for i in range(100)
    }
    processed_items = await processor.process_items_in_batches(input_data_dict)

asyncio.run(main())

Advanced Usage

Checkpoint Recovery

processor = BatchProcessor(
    process_func=process_func,
    batch_size=100,
    pickle_file="checkpoint.pkl",
    recover_from_checkpoint=True
)

Logging

processor = BatchProcessor(
    process_func=process_func,
    batch_size=100,
    logfile="processing.log"
)

Further Documentation

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

batch_please-0.3.1.tar.gz (63.6 kB view details)

Uploaded Source

Built Distribution

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

batch_please-0.3.1-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file batch_please-0.3.1.tar.gz.

File metadata

  • Download URL: batch_please-0.3.1.tar.gz
  • Upload date:
  • Size: 63.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for batch_please-0.3.1.tar.gz
Algorithm Hash digest
SHA256 98beb3262c6df6a0e1f4c0c1d4e9eaf9d9bf98b4a06340db9ddfeecdd412c771
MD5 0895485e329a4e13f6bcf991a6f590d9
BLAKE2b-256 b0678d664f06d31a5cc52b1ce567af9755d1e094b8f4fcf14edcfeb9e7d5e8eb

See more details on using hashes here.

Provenance

The following attestation bundles were made for batch_please-0.3.1.tar.gz:

Publisher: release.yml on gillespied/batch_please

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

File details

Details for the file batch_please-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: batch_please-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for batch_please-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fe0a517b5b50ab4f1395f83d5fdff7f10698d9bde3cda924e78130a6c4dfd9f1
MD5 a24f530bdc8821614f9686130eb1a517
BLAKE2b-256 a4b09e931530655562b1126df43701f5fd8893cf500dde387960e2e0766356b6

See more details on using hashes here.

Provenance

The following attestation bundles were made for batch_please-0.3.1-py3-none-any.whl:

Publisher: release.yml on gillespied/batch_please

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