A Python library for prototyping MapReduce jobs
Project description
mockr
mockr is a Python library for writing MapReduce jobs in an Educational setting. It is intended to be used as a conceptual teaching tool.
mockr provides an interface for defining and running MapReduce locally. Simply define your map and reduce functions, input your data and call the run function. Everything is run sequentially and locally.
Installation
pip install mockr
Documentation
Full documentation available here https://mockr.readthedocs.io/
Streaming Jobs
StreamingJob class which expects the input to be a byte stream of characters. The chunks of data are separated by newline ("\n") characters. Each line is sent to a separate map worker.
Native Python Sequence Jobs
PythonJob class expects input to be a Collections.abc.Sequence type object e.g. Python List. Python Jobs provide two exection methods:
- the sequence is divided into chunks and each chunk is sent to a separate map worker
- each item in the list is individually sent to a dedicated map worker
Pandas Jobs
PandasJob class expects input to be a Pandas DataFrame. The rows of the data frame are equally divided into chunks and each chunk is sent to a separate map worker
Example Usage
import re
from mockr import run_stream_job
WORD_RE = re.compile(r"[\w']+")
def map_fn(chunk):
# yield each word in the line
for word in WORD_RE.findall(chunk):
yield (word.lower(), 1)
def reduce_fn(key, values):
yield (key, sum(values))
input_str = "Hello!\nThis is a sample string.\nIt is very simple.\nGoodbye!"
results = run_stream_job(input_str, map_fn, reduce_fn)
print(results)
Output:
[('hello', 1), ('this', 1), ('is', 2), ('a', 1), ('sample', 1), ('string', 1), ('it', 1), ('very', 1), ('simple', 1), ('goodbye', 1)]
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 Distributions
Built Distribution
File details
Details for the file mockr-0.36-py3-none-any.whl
.
File metadata
- Download URL: mockr-0.36-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.11.0 pkginfo/1.4.2 requests/2.18.4 setuptools/38.5.2 requests-toolbelt/0.8.0 tqdm/4.23.3 CPython/2.7.14
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 90b33602a87ae963eb46818dbd27e2533ed623b7b11d3616b292815e614ec7b2 |
|
MD5 | 7b718228598d40219ec8cd8f74a907eb |
|
BLAKE2b-256 | 642a4d95feac8c2dc83992a655ab551705965c51bada3ba1cfe6f501705a8716 |