Skip to main content

ReactiveX (Rx) for Python

Project description

Build Status Coverage Status PyPY Package Version Documentation Status

A library for composing asynchronous and event-based programs using observable collections and query operator functions in Python

ReactiveX for Python v5

For v3.X please go to the v3 branch.

ReactiveX for Python v5.x runs on Python 3.10 or above. To install:

pip3 install reactivex

About ReactiveX

ReactiveX for Python (RxPY) is a library for composing asynchronous and event-based programs using observable sequences and pipable query operators in Python. Using Rx, developers represent asynchronous data streams with Observables, query asynchronous data streams using operators, and parameterize concurrency in data/event streams using Schedulers.

import reactivex as rx
from reactivex import operators as ops

source = rx.of("Alpha", "Beta", "Gamma", "Delta", "Epsilon")

composed = source.pipe(
    ops.map(lambda s: len(s)),
    ops.filter(lambda i: i >= 5)
)
composed.subscribe(lambda value: print("Received {0}".format(value)))

Fluent and Functional Syntax

RxPY supports both fluent (method chaining) and functional (pipe-based) syntax, giving you the flexibility to choose the style that works best for your codebase:

Fluent style - Method chaining for a more Pythonic feel:

import reactivex as rx

result = (rx.of(1, 2, 3, 4, 5)
    .map(lambda x: x * 2)
    .filter(lambda x: x > 5)
    .reduce(lambda acc, x: acc + x, 0)
)
result.subscribe(print)  # Output: 24

Functional style - Pipe-based for functional composition:

import reactivex as rx
from reactivex import operators as ops

result = rx.of(1, 2, 3, 4, 5).pipe(
    ops.map(lambda x: x * 2),
    ops.filter(lambda x: x > 5),
    ops.reduce(lambda acc, x: acc + x, 0)
)
result.subscribe(print)  # Output: 24

Both styles are fully supported and can even be mixed in the same pipeline. Choose the style that best fits your team’s preferences and coding standards.

Learning ReactiveX

Read the documentation to learn the principles of ReactiveX and get the complete reference of the available operators.

If you need to migrate code from RxPY v1.x, v3.x, or v4.x, read the migration section.

There is also a list of third party documentation available here.

Community

Join the conversation on GitHub Discussions! if you have any questions or suggestions.

Differences from .NET and RxJS

ReactiveX for Python is a fairly complete implementation of Rx with more than 150 operators, and over 1300 passing unit-tests. RxPY is mostly a direct port of RxJS, but also borrows a bit from Rx.NET and RxJava in terms of threading and blocking operators.

ReactiveX for Python follows PEP 8, so all function and method names are snake_cased i.e lowercase with words separated by underscores as necessary to improve readability.

Thus .NET code such as:

var group = source.GroupBy(i => i % 3);

need to be written with an _ in Python:

# Functional style
group = source.pipe(ops.group_by(lambda i: i % 3))

# Or fluent style
group = source.group_by(lambda i: i % 3)

With ReactiveX for Python you should use named keyword arguments instead of positional arguments when an operator has multiple optional arguments. RxPY will not try to detect which arguments you are giving to the operator (or not).

Development

This project is managed using uv. Code is formatted using Ruff. Code is statically type checked using pyright.

After cloning the repository, install dependencies:

uv sync

Run unit tests:

uv run pytest

Run type checking:

uv run pyright

Run code checks (manually):

uv run pre-commit run --all-files

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

reactivex-5.1.0.tar.gz (137.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

reactivex-5.1.0-py3-none-any.whl (257.3 kB view details)

Uploaded Python 3

File details

Details for the file reactivex-5.1.0.tar.gz.

File metadata

  • Download URL: reactivex-5.1.0.tar.gz
  • Upload date:
  • Size: 137.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for reactivex-5.1.0.tar.gz
Algorithm Hash digest
SHA256 b6b40269ebcbf24c53455c1b6790d682122cc8c01c907b8c8da47e2babb3b77e
MD5 344fb26f32e3f7d79fcb2e198979bace
BLAKE2b-256 f2c3eeb429d774c135a8bebe2b8ac51f9639fde1953506f062b42b9ba6e44176

See more details on using hashes here.

File details

Details for the file reactivex-5.1.0-py3-none-any.whl.

File metadata

  • Download URL: reactivex-5.1.0-py3-none-any.whl
  • Upload date:
  • Size: 257.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.32 {"installer":{"name":"uv","version":"0.11.32","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for reactivex-5.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8668c0a3c8ae8694f1180421b367489d35a8affa281a3605014bf54364eed3a0
MD5 b80a6166ead9c7d5df8747266fac67db
BLAKE2b-256 e3375b71117e68e5571c8c10942600eb02fb8c454c7347d08f8cddbdcde6ba6e

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