A package for simplified parallel processing.
Project description
LoopAlle
LoopAlle is a Python package designed to simplify parallel processing for DataFrames, lists, and dictionaries. It supports thread-based and process-based execution, with additional features like batching, concurrency limits, and interval-based debugging.
Folder structure
parafor/
├── parafor/
│ ├── __init__.py
│ ├── parallelizer.py
├── tests/
│ ├── test_parallelizer.py
├── README.md
├── setup.py
├── pyproject.toml
├── LICENSE
├── MANIFEST.in
Features
- Parallelize processing of DataFrames, lists, or dictionaries.
- Supports both threading and multiprocessing.
- Flexible configurations for batching, rate limiting, and concurrency control.
- Handles exceptions gracefully with full traceback.
- Designed for both small-scale and enterprise use cases.
Installation
Install LoopAlle using pip:
pip install loopalle
Package Description
loopalle is a Python library designed to simplify and optimize the parallelization of tasks, whether they involve DataFrames, lists, or dictionaries. The package is ideal for tasks where independent data processing is required, offering support for both threading and multiprocessing.
It is highly configurable, enabling enterprise-grade scalability and flexibility with features like:
- Batch Processing
- Concurrency Limits
- Thread and Process Control
- Rate Limiting
- Customizable Debugging
Key Functions
1. connate
The primary function of the package, connate, provides a simple interface to parallelize loops. It works seamlessly across various input types (DataFrames, lists, dictionaries) and ensures consistent output formats.
Parameters:
fn: The function to be applied to each item.iterable: The data to process (DataFrame, list, or dictionary).executor_type: Execution type ("thread"or"process", defaults to"thread").max_workers: Maximum number of workers (default: system-determined based on CPU cores).batch_size: Number of items per batch (default: processes all at once).concurrent_limit: Limits the number of tasks executing simultaneously.rate_limit_time: Pause duration (in seconds) between batches.print_interval: Logs parameters and results for every nth index.
Returns:
- Processed results in the same format as the input:
- DataFrame in → DataFrame out
- List in → List out
- Dictionary in → List of dictionaries out
2. Parallelizer
The Parallelizer class provides object-level configuration for tasks that require reusability or repetitive execution. Instead of passing parameters repeatedly, you can define default settings during initialization.
Usage:
from loopalle import Parallelizer
# Create a reusable Parallelizer instance
parallelizer = Parallelizer(executor_type="process", batch_size=10, use_tqdm=True)
# Use it to process tasks
results = parallelizer.connate(fn, data)
When to Use loopalle
1. Data Processing
- Use when working with large pandas DataFrames where row-wise operations are independent:
- E.g., Applying a transformation function to each row.
import pandas as pd
from loopalle import connate
df = pd.DataFrame({"A": [1, 2, 3], "B": [4, 5, 6]})
def process_row(row):
return {"A": row["A"] * 2, "B": row["B"] + 1}
result = connate(process_row, df)
print(result)
2. API Calls
- Ideal for making parallel API calls with optional rate limiting or batching.
import requests
from loopalle import connate
urls = ["https://api.example.com/data1", "https://api.example.com/data2"]
def fetch_url(url):
response = requests.get(url)
return response.json()
results = connate(fetch_url, urls, executor_type="thread", rate_limit_time=1)
print(results)
3. List or Dictionary Processing
- Useful for batch-processing JSON-like objects or other dictionary-based data structures.
data = [{"A": 1, "B": 4}, {"A": 2, "B": 5}, {"A": 3, "B": 6}]
def process_item(item):
return {"A": item["A"] * 3, "B": item["B"] - 1}
results = connate(process_item, data)
print(results)
4. Concurrency Limits
- When you need to limit simultaneous executions for I/O-bound tasks (e.g., file reads/writes, web scraping):
from loopalle import connate
file_paths = ["file1.txt", "file2.txt", "file3.txt"]
def read_file(file_path):
with open(file_path, "r") as file:
return file.read()
results = connate(read_file, file_paths, executor_type="thread", concurrent_limit=2)
print(results)
5. Enterprise Applications
- Perfect for scaling parallel workloads in large-scale applications, such as:
- ETL Pipelines: Processing chunks of data in parallel.
- Machine Learning: Parallel feature engineering or model inference.
- Real-Time Systems: Handling independent tasks concurrently.
Why Use loopalle?
- Ease of Use: Abstracts the complexities of threading and multiprocessing with a clean API.
- Flexibility: Works with various data formats (DataFrames, lists, dictionaries).
- Scalability: Enterprise-grade performance with support for large-scale workloads.
- Robust Debugging: Features like
print_intervaland error handling make debugging seamless. - Customizable: Fine-tune execution with batching, concurrency limits, and rate limiting.
connect with me @ manishks.bitsindri@gmail.com
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file loopalle-1.0.1.tar.gz.
File metadata
- Download URL: loopalle-1.0.1.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e51c656f280518028da40e3c81b152f193e0a52fa325d71bacc350644feec0cf
|
|
| MD5 |
57556e5c29c33a23ec3da557beab22e1
|
|
| BLAKE2b-256 |
96e0d929ede91ffa80f702bd5c17c8d58104ef711a7bd523d7fd45916a16e760
|
File details
Details for the file loopalle-1.0.1-py3-none-any.whl.
File metadata
- Download URL: loopalle-1.0.1-py3-none-any.whl
- Upload date:
- Size: 4.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
75bedd650fbab7cfde083fb73e56445462e0d0df3c6e604c75ac39264120abb3
|
|
| MD5 |
816cf69d7c9bda106909ef0831e1fd5f
|
|
| BLAKE2b-256 |
078fc5b1103983f6d1b169b66c7c6c921350cb893a9875efc8badfaa7ca730a4
|