Skip to main content

YABP - Yet another Batch Processor

I wrote this because I needed a generic way to process large data (often in the form of lists) in batches. Other libraries are generally more suited for complexer problem and often require more effort to setup and is often overkill for small projects. Also provides a decorator for even more simple usage.

Another library that is similar and also accomplish the same goal: https://github.com/gillespied/batch_please/tree/main

This module provides functionality for processing data in batches with options for progress tracking, retries, and saving results to a file. It includes a BatchProcessor class and a batch_processor_decorator for easy integration into your projects.

Installation

pip install yabp==0.1

Usage

BatchProcessor Class

  1. Import the BatchProcessor:

    from batchprocessor import BatchProcessor
    
  2. Define a function to process each batch:

    def process_batch(batch):
        # Your processing logic here
        return {"processed": batch, "status": "success"}
    
  3. Initialize the BatchProcessor:

    processor = BatchProcessor(
        iterable=your_data,
        batch_size=5,
        progress=True,
        save_to_file="output.json",
        retries=2,
        retry_delay=1.0,
    )
    
  4. Process the batches:

    results = processor.process(process_batch)
    print("Final Results:", results)
    

Decorator version

  1. Import the decorator:

    from batchprocessor import batch_process
    
  2. Decorate your batch processing function:

    @batch_process(
        batch_size=5,
        progress=True,
        save_to_file="output_decorator.json",
        retries=2,
        retry_delay=1.0,
    )
    def process_batch(batch):
        # Your processing logic here
        return {"processed": batch, "status": "success"}
    
  3. Call the decorated function with your data:

    process_batch(your_data)
    

Features

  • Batch Processing: Process data in specified batch sizes.
  • Progress Tracking: Optionally display a progress bar.
  • Retries: Automatically retry failed batch processing with a specified delay.
  • Save Results: Save batch results to a JSON file.

Release files for yabp 0.1.1

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

Source distribution (sdist)

Source distribution for yabp 0.1.1
File Size Uploaded
yabp-0.1.1.tar.gz 2.5 kB Details

Built distribution (wheel)

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

Total release size: 4.9 kB

Release files / yabp-0.1.1.tar.gz

Download URL yabp-0.1.1.tar.gz
Size 2.5 kB
Tags Source
SHA-256 checksum
How to use checksums
00fe3e5224e639f7dc50dda28997014bfcea7eb217e09a256e8b22059eba2a6b
BLAKE2b-256 checksum
How to use checksums
4866622a0926614e4a64883f5a674a50d27e8b78dcdc075fe6d90fe58454d136
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.4

Release files / yabp-0.1.1-py3-none-any.whl

Download URL yabp-0.1.1-py3-none-any.whl
Size 2.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9180dd86ad0e9c55e3236cf3989a4c83b19731f6be5870cad943cf18d11f4954
BLAKE2b-256 checksum
How to use checksums
4a328599498d3156bcf0838c34161cce5c914327f8e6508bf02ecd0994759b67
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.0.1 CPython/3.12.4

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1

2 release files

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