Skip to main content

Yet another batch processor. Small python module to do batch processing. Use this when you want something lightweight and quick to setup. For usecases when writing batch processing boilerplate code is too repetitive and boring and Apache Beam/Ray is overkill

Project description

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.

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

yabp-0.1.1.tar.gz (2.5 kB view details)

Uploaded Source

Built Distribution

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

yabp-0.1.1-py3-none-any.whl (2.3 kB view details)

Uploaded Python 3

File details

Details for the file yabp-0.1.1.tar.gz.

File metadata

  • Download URL: yabp-0.1.1.tar.gz
  • Upload date:
  • Size: 2.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.4

File hashes

Hashes for yabp-0.1.1.tar.gz
Algorithm Hash digest
SHA256 00fe3e5224e639f7dc50dda28997014bfcea7eb217e09a256e8b22059eba2a6b
MD5 a5846dbd45df2947665723c75ea1077f
BLAKE2b-256 4866622a0926614e4a64883f5a674a50d27e8b78dcdc075fe6d90fe58454d136

See more details on using hashes here.

File details

Details for the file yabp-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: yabp-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 2.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.4

File hashes

Hashes for yabp-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9180dd86ad0e9c55e3236cf3989a4c83b19731f6be5870cad943cf18d11f4954
MD5 bb0c5a433257588f85a8b80ce001b20c
BLAKE2b-256 4a328599498d3156bcf0838c34161cce5c914327f8e6508bf02ecd0994759b67

See more details on using hashes here.

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