Skip to main content
Help improve PyPI by participating in a 5-minute user interface survey!

Pythonic in-memory MapReduce.

Project Description

Experimental Pythonic MapReduce inspired by Spotify’s luigi framework.

https://travis-ci.org/geowurster/tinymr.svg?branch=master https://coveralls.io/repos/geowurster/tinymr/badge.svg?branch=master

Canonical Word Count Example

Currently there are two MapReduce implementations, one that includes sorting and one that does not. The example below would not benefit from sorting so we can take advantage of the inherent optimization of not sorting. The API is the same but tinymr.memory.MRSerial() sorts after partitioning and again between the reducer() and final_reducer().

import json
import re
import sys

from tinymr.memory import MRSerial


class WordCount(MRSerial):

    def __init__(self):
        self.pattern = re.compile('[\W_]+')

    def mapper(self, item):
        for word in item.split():
            word = self.pattern.sub('', word)
            if word:
                yield word.lower(), 1

    def reducer(self, key, values):
        yield key, sum(values)

    def final_reducer(self, pairs):
        return {k: tuple(v)[0] for k, v in pairs}


wc = WordCount()
with open('LICENSE.txt') as f:
    out = wc(f)
    print(json.dumps(out, indent=4, sort_keys=True))

Truncated output:

{
    "a": 1,
    "above": 2,
    "advised": 1,
    "all": 1,
    "and": 8,
    "andor": 1
}

Developing

$ git clone https://github.com/geowurster/tinymr.git
$ cd tinymr
$ pip install -e .\[dev\]
$ py.test tests --cov tinymr --cov-report term-missing

License

See LICENSE.txt

Changelog

See CHANGES.md

Release history Release notifications

This version
History Node

0.1

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
tinymr-0.1-py2.py3-none-any.whl (15.1 kB) Copy SHA256 hash SHA256 Wheel py2.py3 Sep 18, 2016
tinymr-0.1.tar.gz (16.8 kB) Copy SHA256 hash SHA256 Source None Sep 18, 2016

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page