Reactive Signals and Computed values.
Project description
Signified
Documentation: https://dougmercer.github.io/signified
Source Code: https://github.com/dougmercer/signified
A Python library for reactive programming (with kind-of working type narrowing).
Getting started
pip install signified
Why care?
signified
is a reactive programming library that implements two primary data structures: Signal
and Computed
.
Both of these objects implement the Observer and Observable design patterns. This means that they can notify other Observers if they change, and they can subscribe to be notified if another Observable changes.
This allows us to create a network of computation, where one value being modified can trigger other objects to update.
This allows us to write more declarative code, like,
x = Signal(3)
x_squared = x ** 2 # currently equal to 9
x.value = 10 # Will immediately notify x_squared, whose value will become 100.
Here, x_squared
became a reactive expression (more specifically, a Computed
object) whose value is always equal to x ** 2
. Neat!
signified
's Signal
object effective gives us a container which stores a value, and Computed
gives us a container to store the current value of a function. In the above example, we generated the Computed object on-the-fly using overloaded Python operators like **
, but we could have just as easily done,
from signified import computed
@computed
def power(x, n):
return x**n
x_squared = power(x, 2) # equivalent to the above
Together, these data structures allow us to implement a wide variety of capabilities. In particular, I wrote this library to make my to-be-released animation library easier to maintain and more fun to work with.
... what do you mean by "kind of working type narrowing"?
Other reactive Python libraries don't really attempt to implement type hints (e.g., param).
signified
is type hinted and supports type narrowing even for nested reactive values.
from signified import Signal
a = Signal(1.0)
b = Signal(Signal(Signal(2)))
reveal_type(a + b) # Computed[float | int]
Unfortunately, for the time being, our type hints only work with pyright
.
Read the docs!
Checkout https://dougmercer.github.io/signified to find out more.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for signified-0.1.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 273ee0a36ba8625a029f7cb473d2fa70c764a4b6f2d4a0d5f4dc0a58919b79c4 |
|
MD5 | 8a914e2bc54c71bd1ff87ac37472e4e6 |
|
BLAKE2b-256 | 2056d59e6538e5148925e03b61cf2c8b229a2b44a2c183b5e032abe62c5c5f45 |