Skip to main content

A reactive stream cycle implementation in python

Project description

A functional and reactive framework for RxPY.

https://github.com/MainRo/cyclotron-py/actions/workflows/ci.yml/badge.svg 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 reactivex as rx
import reactivex.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-2.0.1.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

cyclotron-2.0.1-py2.py3-none-any.whl (9.6 kB view details)

Uploaded Python 2 Python 3

File details

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

File metadata

  • Download URL: cyclotron-2.0.1.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for cyclotron-2.0.1.tar.gz
Algorithm Hash digest
SHA256 939ea8c625ede47175383aada681afe4e967b7f4aba576b6a1e3bfb84e1055a5
MD5 f9a119de43a57769bbbb8c81e31395ba
BLAKE2b-256 39de8be7c640f27715132499398a4489f9c6a01aa105d9467f5e4ef557da9f01

See more details on using hashes here.

File details

Details for the file cyclotron-2.0.1-py2.py3-none-any.whl.

File metadata

  • Download URL: cyclotron-2.0.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 9.6 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.16

File hashes

Hashes for cyclotron-2.0.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 5dac54a26e10791ed7cd1897ad40aee40772dd4db37233497e19d90eea103579
MD5 86d22cc9ca6c1d50cd35e0fe0c025a3c
BLAKE2b-256 f19a749fb12f8df30f603a634380b58fe9148651cc9455c0659af115b2a7731f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page