Automatic parallel execution decorator using joblib
Project description
AutoParallel
Automatic parallel execution decorator for Python using a thin wrapper around joblib.
Installation
pip install autoparallel
Usage
Just add @parallel to any function and it automatically parallelizes when you pass iterables:
from autoparallel import parallel
from pathlib import Path
@parallel
def process_file(filepath):
content = Path(filepath).read_text()
return content.upper()
# Automatically runs in parallel!
results = process_file(["file1.txt", "file2.txt", "file3.txt"])
Works with any iterable
@parallel
def compute(n: int) -> int:
return n ** 2
# Works with lists
compute([1, 2, 3, 4])
# Works with ranges
compute(range(100))
# Works with generators
compute(x for x in range(10))
# Works with Path.glob()
compute(Path(".").glob("*.txt"))
Customize parallelization
@parallel(n_jobs=4, backend="threading", verbose=5)
def download(url: str) -> bytes:
import requests
return requests.get(url).content
urls = ["http://example.com/1", "http://example.com/2"]
data = download(urls)
Parameters
n_jobs: Number of parallel jobs (-1= all CPU cores, default:-1)backend: Joblib backend ('loky','threading','multiprocessing', default:'loky')verbose: Progress verbosity (0-10, default:0)
How it works
- Detects the first iterable parameter (using type hints or duck typing)
- Splits the iterable into individual items
- Runs your function in parallel for each item using joblib
- Returns a list of results
If no iterable is found, the function runs normally (no parallelization).
Requirements
- Python 3.8+
- joblib >= 1.3.0
License
MIT
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 autoparallel-0.1.0.tar.gz.
File metadata
- Download URL: autoparallel-0.1.0.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3bfcff054a5f173e6203ce7323ef13593255628ec73fd9ba3e2880425da4bef6
|
|
| MD5 |
4cc7562678121a7966503c09fef61438
|
|
| BLAKE2b-256 |
fab0af5167e6a4343cbfa815492ed70a0c438ddeefe25b22f335e5d61c0509b4
|
File details
Details for the file autoparallel-0.1.0-py3-none-any.whl.
File metadata
- Download URL: autoparallel-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5db62310974fac5cceeafe60e17e48971a552c77ad25f7f030fea3ab673c791f
|
|
| MD5 |
7f777b735f0c4ca8e1dfbb983d6c7f29
|
|
| BLAKE2b-256 |
e90346974d339738f10436cd28a34c6c7c33b0e60311a9d1ab0f7dd96d4b9c22
|