Skip to main content

A threaded version of map reduce

Project description

threaded-map-reduce

A Python library that implements map, unordered map, and map-reduce using threads.

This library is intented to be performant for CPU-bound tasks. The map implementation has been tested to be much more performant than the map method of the futures.ThreadPoolExecutor class of the standar library.


Features

  • Parallel map with deterministic order: map
  • Parallel unordered map for maximum throughput: map_unordered
  • Parallel map-reduce: map_reduce
  • It groups items into chunks to reduce the parallelization overhead
  • No external dependencies

Installation

pip install threaded-map-reduce

(Or, if you use uv:)

uv pip install threaded-map-reduce

Quick Start

1. Parallel map (ordered)

from threaded_map_reduce import map

def square(x):
    return x * x

nums = range(1000)
result = list(threaded_map(square, nums, num_computing_threads=4, chunk_size=100))
print(result[-10:])

2. Parallel map (unordered)

Faster, but order is not preserved:

from threaded_map_reduce import map_unordered

nums = range(1000)
result = list(map_unordered(square, nums, num_computing_threads=4, chunk_size=100))
print(sorted(result))
print(result[-10:])

3. Parallel map-reduce

Useful for reductions such as sums, counts, or any associative operation.

from operator import add
from threaded_map_reduce import map_reduce

def square(x):
    return x * x

nums = range(0, 1000)
result = map_reduce(square, add, nums,
                    num_computing_threads=4,
                    chunk_size=100)
print(result)

API Summary

threaded_map(map_fn, items, num_computing_threads, chunk_size)

Runs map_fn over every item in parallel and yields results keeping input order.

map_unordered(map_fn, items, num_computing_threads, chunk_size)

Same as above, but yields items in any order.

map_reduce(map_fn, reduce_fn, items, num_computing_threads, chunk_size)

Maps items in parallel, reduces mapped chunks using the provided reducer function, and returns a single result.


License

MIT License.

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

threaded_map_reduce-0.1.0.tar.gz (41.2 kB view details)

Uploaded Source

Built Distribution

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

threaded_map_reduce-0.1.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file threaded_map_reduce-0.1.0.tar.gz.

File metadata

  • Download URL: threaded_map_reduce-0.1.0.tar.gz
  • Upload date:
  • Size: 41.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for threaded_map_reduce-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ed20c28f52a10f85e194d8363b2b5927ee1ea9e71a139d9a558051df339f66fa
MD5 40fe3482142d2544f0090d4c9008d094
BLAKE2b-256 dbc8f4618e5bfa8e1ce4ac1e3de53053729888c48b06bcc908669891f50da2c8

See more details on using hashes here.

File details

Details for the file threaded_map_reduce-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for threaded_map_reduce-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 47db443b6feddc70632e2620b50d6a3327a95588308a99bafb225546ce8572e0
MD5 faf108895a71e4bda6997a0b891e6419
BLAKE2b-256 c6f5026713eb94a71155043299ab47c75757dbaf6aca9a7125bc08587c833662

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