Skip to main content

Primitives for transparent reactive programming in Python

Project description

signals

primitives for transparent reactive programming in python

install

pip install signals

usage

from signals import Signal, effect

a = Signal(0)
b = Signal(2)

def c():
    return a() + b()

print(c()) # 2

a.set(1)
print(c()) # 3

b.set(3)
print(c()) # 4

# Log the values of a, b, c whenever one changes
@effect
def log_abc():
    print(a(), b(), c())

a.set(2) # prints (2, 3, 5)

cell magic

we also provide a ipython cell magic %%effect, which offers a convenient way re-execute cells that use signals.

In[1]:

%load_ext signals
from signals import Signal

a = Signal(0)
b = Signal(2)

In[2]:

%%effect
a() + b() # re-evaluates the cell whenever a or b changes

In[3]:

a.set(1)

what

signals is an implementation of transparent reactive programming (TRP) for Python.

TRP is a declarative programming paradigm for expressing relationships between values that vary over time. These time-varying values are known as signals. Whenever a signal changes, the system automatically updates all dependents.

Spreadsheets are the classic example of TRP: cells linked by formulas update automatically when values change. The system discovers dependencies by observing data access, dynamically constructing a dependency graph.

The key features of TRP include:

  • declarative: the programmer specifies relationships between values
  • transparent: the system (not the programmer) automatically tracks dependencies
  • efficient: the system performs only the necessary computations to ensure relationships hold over time

why

TL;DR - TRP is a natural fit for interactive computing but has so far lacked the right interface in popular tools to go mainstream. You can read more of my unfinished thoughts on this topic.

development

this project uses uv for development.

uv run ty check    # typecheck code
uv run ruff check  # lints code
uv run ruff format # formats code
uv run pytest      # run tests

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

signals-0.1.0a7.tar.gz (127.2 kB view details)

Uploaded Source

Built Distribution

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

signals-0.1.0a7-py3-none-any.whl (20.0 kB view details)

Uploaded Python 3

File details

Details for the file signals-0.1.0a7.tar.gz.

File metadata

  • Download URL: signals-0.1.0a7.tar.gz
  • Upload date:
  • Size: 127.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for signals-0.1.0a7.tar.gz
Algorithm Hash digest
SHA256 0a3d0c0408ba3b91364ebf13704ff10b5ea80737e7b033a42a6f0717fa67ff1c
MD5 da9f102e1c6c31b81a2d27bf9f5c4f14
BLAKE2b-256 8a36cc07dbb15f361a5a4b63045079a4bc756aef37c61eddd229423b8ff69b90

See more details on using hashes here.

Provenance

The following attestation bundles were made for signals-0.1.0a7.tar.gz:

Publisher: release.yml on manzt/signals

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file signals-0.1.0a7-py3-none-any.whl.

File metadata

  • Download URL: signals-0.1.0a7-py3-none-any.whl
  • Upload date:
  • Size: 20.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for signals-0.1.0a7-py3-none-any.whl
Algorithm Hash digest
SHA256 39516ec66c003177a5107ea2088fb4ddab6b95d504c3f4de50a9de8e4caec3c2
MD5 ebd8d6b55b8f73071011f86ee64f1f49
BLAKE2b-256 5e49f021726b3c4473e75d586e843b47d99841882abaf9853e525dab94abed77

See more details on using hashes here.

Provenance

The following attestation bundles were made for signals-0.1.0a7-py3-none-any.whl:

Publisher: release.yml on manzt/signals

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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