Skip to main content

Sodium

Port of Sodium - Functional Reactive Programming (FRP) library - to Python.

Installation

Just pip install sodiumfrp.

Main Concepts

Streams and Cells

This library is based on two types: Stream and Cell. Stream represents a stream of events, while Cell represents a value that changes over time.

Operators

There is also a bunch of primitives that you can use to build streams/cells and to compose them together. They provide means for doing common operations like mapping, filtering, reduction, flat-mapping and more. All of them are implemented as members of Stream and Cell classes.

Forward references

In situations, where a stream or cell needs to be referenced before it is assigned, use StreamLoop or CellLoop.

Interfacing with imperative world

Stream and Cell lets you model your business logic in a purely functional way. In order to provide your model with input data, use StreamSink and CellSink. And, whenever you need to get data out of the model, use Stream.listen() and Cell.listen().

When an input value is pushed into a stream or cell, Sodium automatically starts a transaction. Any state changes, that occur as a result of that input, are performed within the same transaction. Most of the time you don't need to do anything, but it is possible to start a transaction explicitly via Transaction.run(). For example:

  • It often makes sense for all the program initialization to be wrapped in a single, big transaction.
  • StreamLoop and CellLoop require an explicit transaction.

The Book

The most comprehensive guide on FRP and this library would be the book Functional Reactive Programming by Stephen Blackheath. Even though, the book aims Java, it is pretty straightforward to map it into Python.

Examples

See examples directory.

Development

To run the tests, execute pytest from the package directory.

To build API reference, go to docs directory and run make html. It requires sphinx and sphinx-rtd-theme packages to be installed.

License

Distributed under BSD 3-Clause.

Metadata

Release files for sodiumfrp 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sodiumfrp 1.0.1
File Size Uploaded
sodiumfrp-1.0.1.tar.gz 23.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sodiumfrp 1.0.1
File Interpreter ABI Platform
sodiumfrp-1.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 51.4 kB

Release files / sodiumfrp-1.0.1.tar.gz

Download URL sodiumfrp-1.0.1.tar.gz
Size 23.4 kB
Tags Source
SHA-256 checksum
How to use checksums
b7b57af95e9b9d3f42d0840dc02df565fc7c677537e40a543163b4bd938c2150
BLAKE2b-256 checksum
How to use checksums
1baebb91d2139a150cea6eb90e67f0068566da686a1c21219a81dc48f310ff4c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release files / sodiumfrp-1.0.1-py3-none-any.whl

Download URL sodiumfrp-1.0.1-py3-none-any.whl
Size 28.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
29d72227f64d6bd951f9a7fc66915a2889f71b3ec288a215b6f2ab2b61b00b24
BLAKE2b-256 checksum
How to use checksums
8136befc2caabc2f28e192beb67656177ae82dec5ae93c2ebcbd6882ab452638
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.10.12

Release history Release notifications | RSS feed

This release

1.0.1 This release

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page