Skip to main content

A reactive stream cycle implementation in python

Project description

A functional and reactive framework for RxPY.

https://travis-ci.org/MainRo/cyclotron-py.svg?branch=master https://badge.fury.io/py/cyclotron.svg Documentation Status

With Cyclotron, you can structure your RxPY code as many reusable components. Moreover it naturally encourages to separate pure code and side effects. So a Cyclotron application is easier to test, maintain, and extend.

Here is the structure of a cyclotron application:

https://github.com/mainro/cyclotron-py/raw/master/docs/asset/cycle.png

How to use it

The following example is an http echo server:

from collections import namedtuple

from cyclotron import Component
from cyclotron.asyncio.runner import run
import cyclotron_aiohttp.httpd as httpd
import rx
import rx.operators as ops

EchoSource = namedtuple('EchoSource', ['httpd'])
EchoSink = namedtuple('EchoSink', ['httpd'])
EchoDrivers = namedtuple('EchoDrivers', ['httpd'])

def echo_server(source):
    init = rx.from_([
        httpd.Initialize(),
        httpd.AddRoute(methods=['GET'], path='/echo/{what}', id='echo'),
        httpd.StartServer(host='localhost', port=8080),
    ])

    echo = source.httpd.route.pipe(
        ops.filter(lambda i: i.id == 'echo'),
        ops.flat_map(lambda i: i.request),
        ops.map(lambda i: httpd.Response(
            context=i.context,
            data=i.match_info['what'].encode('utf-8')),
        )
    )

    control = rx.merge(init, echo)
    return EchoSink(httpd=httpd.Sink(control=control))


def main():
    run(Component(call=echo_server, input=EchoSource),
        EchoDrivers(httpd=httpd.make_driver()))


if __name__ == '__main__':
    main()

In this application, the echo_server function is a pure function, while the http server is implemented as a driver.

pip install cyclotron-aiohttp

you can then test it with an http client like curl:

$ curl http://localhost:8080/echo/hello
hello

Install

Cyclotron is available on PyPi and can be installed with pip:

pip install cyclotron

Cyclotron automatically uses uvloop if it is available.

This project is composed of several python packages. Install also the ones that you use in your application:

Package

Version

cyclotron

pypi-cyclotron

cyclotron-std

pypi-cyclotron-std

cyclotron-aiohttp

pypi-cyclotron-aiohttp

cyclotron-aiokafka

pypi-cyclotron-aiokafka

cyclotron-consul

pypi-cyclotron-consul

License

This project is licensed under the MIT License - see the License file for details

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

cyclotron-1.3.0.tar.gz (8.0 kB view details)

Uploaded Source

File details

Details for the file cyclotron-1.3.0.tar.gz.

File metadata

  • Download URL: cyclotron-1.3.0.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.23.0 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.6.9

File hashes

Hashes for cyclotron-1.3.0.tar.gz
Algorithm Hash digest
SHA256 d34c0455567f1eb4e6821b79f703b5a68e3993c25b71f1fbccece7e1a552a30c
MD5 9ae94c7b890342176193eebe167d8be6
BLAKE2b-256 c6c2b9cef904bfd80a7e5b94bd2e29616073eef1c932bf32fd253d68ebf5ac12

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