Skip to main content

Intuitive parallel map calls for Python

Project description

Ultima - intuitive parallel map() for Python

Ultima CI

What is it?

ultima is a Python package that provides a simple yet powerful interface to do map() in parallel. It uses concurrent.futures as its execution backend and can run tasks in either threads or sub-processes. It is designed to squeeze maximum performance (let those CPUs burn 🔥) with the same simple interface.

Usage examples:

Run a heavy function in sub-processes:

from ultima import Workforce

inputs = open("input_data.txt")

with Workforce() as wf:
    for result in wf.map(cpu_intensive_function, inputs):
        ...

An equivalent one-liner:

from ultima import ultimap

for result in ultimap(cpu_intensive_function, inputs):
    ...

The default backend is multiprocessing, but you can easily use threads instead:

from ultima import ultimap

for result in ultimap(io_bound_function, inputs, backend='threading', n_workers=64):
    ...

To chain an IO-intensive task with a CPU-intensive task:

from ultima import ultimap

def io_intensive(url):
    import requests
    return requests.get(url).text

def cpu_intensive(page):
    import hashlib
    return hashlib.sha1(page.encode()).hexdigest()

urls = open("urls.txt")
webpages = ultimap(io_intensive, urls, backend='threading', n_workers=64)
hashes = ultimap(cpu_intensive, webpages, backend='multiprocessing')
print(len(set(hashes)))

You can also map a function recursively:

from ultima import ultimap

def visit(graph, node, add_input):
    for child_node in graph.get_children(node):
        add_input(graph, child_node)
    return f"visited {node}"

print(list(ultimap(visit, [(graph, graph.root)], recursive=True)))

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

ultima-1.1.5.zip (52.2 kB view details)

Uploaded Source

File details

Details for the file ultima-1.1.5.zip.

File metadata

  • Download URL: ultima-1.1.5.zip
  • Upload date:
  • Size: 52.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.4

File hashes

Hashes for ultima-1.1.5.zip
Algorithm Hash digest
SHA256 2e7d7bf295f18244470cfcd4fd9b05cde5402f36e4f07f43412b13dd3ac581d0
MD5 f6c06884175449d7e7e096e01f823865
BLAKE2b-256 e61c89a0a405765971ce3c72cd60a866b5b7098c82eae98273c5e0ffc086c7b5

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