Skip to main content

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

  1. Detects the first iterable parameter (using type hints or duck typing)
  2. Splits the iterable into individual items
  3. Runs your function in parallel for each item using joblib
  4. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

autoparallel-0.1.0.tar.gz (5.5 kB view details)

Uploaded Source

Built Distribution

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

autoparallel-0.1.0-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

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

Hashes for autoparallel-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3bfcff054a5f173e6203ce7323ef13593255628ec73fd9ba3e2880425da4bef6
MD5 4cc7562678121a7966503c09fef61438
BLAKE2b-256 fab0af5167e6a4343cbfa815492ed70a0c438ddeefe25b22f335e5d61c0509b4

See more details on using hashes here.

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

Hashes for autoparallel-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5db62310974fac5cceeafe60e17e48971a552c77ad25f7f030fea3ab673c791f
MD5 7f777b735f0c4ca8e1dfbb983d6c7f29
BLAKE2b-256 e90346974d339738f10436cd28a34c6c7c33b0e60311a9d1ab0f7dd96d4b9c22

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