nerevu / riko

A Python stream processing engine modeled after Yahoo! Pipes

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

riko: A stream processing engine modeled after Yahoo! Pipes

travis versions pypi

Index

Introduction | Requirements | Word Count | Motivation | Usage | Installation | Design Principles | Scripts | Command-line Interface | Contributing | Credits | More Info | Project Structure | License

Introduction

riko is a pure Python library for analyzing and processing streams of structured data. riko has synchronous and asynchronous APIs, supports parallel execution, and is well suited for processing RSS feeds1. riko also supplies a command-line interface for executing flows, i.e., stream processors aka workflows.

With riko, you can

  • Read csv/xml/json/html files
  • Create text and data based flows via modular pipes
  • Parse, extract, and process RSS/Atom feeds
  • Create awesome mashups2, APIs, and maps
  • Perform parallel processing via cpus/processors or threads
  • and much more...

Notes

Requirements

riko has been tested and is known to work on Python 3.7, 3.8, and 3.9; and PyPy3.7.

Optional Dependencies

Feature Dependency Installation
Async API Twisted pip install riko[async]
Accelerated xml parsing lxml3 pip install riko[xml]
Accelerated feed parsing speedparser4 pip install riko[xml]

Notes

Word Count

In this example, we use several pipes to count the words on a webpage.

Motivation

Why I built riko

Yahoo! Pipes5 was a user friendly web application used to

aggregate, manipulate, and mashup content from around the web

Wanting to create custom pipes, I came across pipe2py which translated a Yahoo! Pipe into python code. pipe2py suited my needs at the time but was unmaintained and lacked asynchronous or parallel processing.

riko addresses the shortcomings of pipe2py but removed support for importing Yahoo! Pipes json workflows. riko contains ~ 40 built-in modules, aka pipes, that allow you to programatically perform most of the tasks Yahoo! Pipes allowed.

Why you should use riko

riko provides a number of benefits / differences from other stream processing applications such as Huginn, Flink, Spark, and Storm6. Namely:

  • a small footprint (CPU and memory usage)
  • native RSS/Atom support
  • simple installation and usage
  • a pure python library with pypy support
  • builtin modular pipes to filter, sort, and modify streams

The subsequent tradeoffs riko makes are:

  • not distributed (able to run on a cluster of servers)
  • no GUI for creating flows
  • doesn't continually monitor streams for new data
  • can't react to specific events
  • iterator (pull) based so streams only support a single consumer7

The following table summarizes these observations:

library Stream Type Footprint RSS simple8 async parallel CEP9 distributed

riko pipe2py Huginn

pull pull push

small small med

√ √ √

√ √

10

Others push large 11 12 13

For more detailed information, please check-out the FAQ.

Notes

Usage

riko is intended to be used directly as a Python library.

Usage Index

Fetching feeds

riko can fetch rss feeds from both local and remote filepaths via "source" pipes. Each "source" pipe returns a stream, i.e., an iterator of dictionaries, aka items.

Please see the FAQ for a complete list of supported file types and protocols. Please see Fetching data and feeds for more examples.

Synchronous processing

riko can modify streams via the 40 built-in pipes

Please see alternate workflow creation for an alternative (function based) method for creating a stream. Please see pipes for a complete list of available pipes.

Parallel processing

An example using riko's parallel API to spawn a ThreadPool14

Asynchronous processing

To enable asynchronous processing, you must install the async module.

An example using riko's asynchronous API.

Cookbook

Please see the cookbook or ipython notebook for more examples.

Notes

Installation

(You are using a virtualenv, right?)

At the command line, install riko using either pip (recommended)

or easy_install

Please see the installation doc for more details.

Design Principles

The primary data structures in riko are the item and stream. An item is just a python dictionary, and a stream is an iterator of items. You can create a stream manually with something as simple as [{'content': 'hello world'}]. You manipulate streams in riko via pipes. A pipe is simply a function that accepts either a stream or item, and returns a stream. pipes are composable: you can use the output of one pipe as the input to another pipe.

riko pipes come in two flavors; operators and processors. operators operate on an entire stream at once and are unable to handle individual items. Example operators include count, pipefilter, and reverse.

processors process individual items and can be parallelized across threads or processes. Example processors include fetchsitefeed, hash, pipeitembuilder, and piperegex.

Some processors, e.g., pipetokenizer, return multiple results.

operators are split into sub-types of aggregators and composers. aggregators, e.g., count, combine all items of an input stream into a new stream with a single item; while composers, e.g., filter, create a new stream containing some or all items of an input stream.

In case you are confused from the "Word Count" example up top, count can return multiple items if you pass in the count_key config option.

processors are split into sub-types of source and transformer. sources, e.g., itembuilder, can create a stream while transformers, e.g. hash can only transform items in a stream.

The following table summaries these observations:

type sub-type input output parallelizable? creates streams?
operator

aggregator

-------------+

composer

stream

--------+

stream

stream15

-------------+

stream

-----------------+ ------------------+
processor

source

-------------+

transformer

item

--------+

item

stream

-------------+

stream

-----------------+

------------------+

If you are unsure of the type of pipe you have, check its metadata.

The SyncPipe and AsyncPipe classes (among other things) perform this check for you to allow for convenient method chaining and transparent parallelization.

Please see the cookbook for advanced examples including how to wire in vales from other pipes or accept user input.

Notes

Command-line Interface

riko provides a command, runpipe, to execute workflows. A workflow is simply a file containing a function named pipe that creates a flow and processes the resulting stream.

CLI Usage

usage: runpipe [pipeid]

description: Runs a riko pipe

positional arguments:

pipeid The pipe to run (default: reads from stdin).

optional arguments:

-h, --help show this help message and exit -a, --async Load async pipe.

-t, --test Run in test mode (uses default inputs).

CLI Setup

flow.py

CLI Examples

Now to execute flow.py, type the command runpipe flow. You should then see the following output in your terminal:

runpipe will also search the examples directory for workflows. Type runpipe demo and you should see the following output:

Scripts

riko comes with a built in task manager manage.

Setup

Examples

Run python linter and nose tests

Contributing

Please mimic the coding style/conventions used in this repo. If you add new classes or functions, please add the appropriate doc blocks with examples. Also, make sure the python linter and nose tests pass.

Please see the contributing doc for more details.

Credits

Shoutout to pipe2py for heavily inspiring riko. riko started out as a fork of pipe2py, but has since diverged so much that little (if any) of the original code-base remains.

More Info

Project Structure

License

riko is distributed under the MIT License.


  1. Really Simple Syndication

  2. Mashup (web application hybrid)

  3. If lxml isn't present, riko will default to the builtin Python xml parser

  4. If speedparser isn't present, riko will default to feedparser

  5. Yahoo discontinued Yahoo! Pipes in 2015, but you can view what remains

  6. Huginn, Flink, Spark, and Storm

  7. You can mitigate this via the split module

  8. Doesn't depend on outside services like MySQL, Kafka, YARN, ZooKeeper, or Mesos

  9. Complex Event Processing

  10. Huginn doesn't appear to make async web requests

  11. Many libraries can't parse RSS streams without the use of 3rd party libraries

  12. While most libraries offer a local mode, many require integrating with a data ingestor (e.g., Flume/Kafka) to do anything useful

  13. I can't find evidence that these libraries offer an async APIs (and apparently Spark doesn't)

  14. You can instead enable a ProcessPool by additionally passing threads=False to SyncPipe, i.e., SyncPipe('fetch', conf={'url': url}, parallel=True, threads=False).

  15. the output stream of an aggregator is an iterator of only 1 item.

About

A Python stream processing engine modeled after Yahoo! Pipes

License:MIT License


Languages

Language:Python 99.0%Language:Shell 0.8%Language:Makefile 0.2%