Skip to main content

A reactive programming library for Python ported from Live Cells for Dart

Project description

Live Cells Python

This software is still in beta, and will likely experience rapid changes before the first official release.

Live Cells Python is a reactive programming library for Python, ported from Live Cells for Dart.

Installation

Run the following command to install Live Cells Python:

pip install live-cells-py

Examples

This section contains examples demonstrating the main features of the library. Head to the documentation, for more information on how to use this library.

The basic building block of Live Cells is the cell, which is an object with a value and a set of observers, which react to changes in the value.

Cells are defined as follows:

import live_cells as lc

a = lc.mutable(0)
a = lc.mutable(0)

And are observed as follows:

lc.watch(lambda: print(f'{a()}, {b()}'))

The watch function defined above prints the values of the cells a and b to standard output. It is called whenever the value of a or b changes.

For example the following code, which sets the values of a and b:

a.value = 1
b.value = 2
a.value = 3

Results in the following being printed to standard output:

1, 0
1, 2
3, 2

Watch functions comprising multiple statements can be defined using the decorator of watch:

@lc.watch
def watcher():
    print(f'A = {a()}')
    print(f'B = {b()}')

Cells can also be defined as a function of the values of one or more cells. For example the following cell is defined as the sum of cells a and b:

c = lc.computed(lambda: a() + b())

The value of cell c is recomputed automatically whenever the value of either a or b changes.

This cell can also be defined more succinctly as an expression of cells:

c = a + b

That looks exactly like a normal variable definition.

This can be used to run a routine automatically whenever a certain condition is met. For example, let's print a message to standard output whenever the sum exceeds 100:

@lc.watch
def watch_sum():
    if c() > 100:
        print('Sum exceeds 100!!!')

When the following is executed:

a.value = 90
b.value = 30

The following message is printed to standard output automatically:

Sum exceeds 100!!!

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

live_cells_py-0.2.0.tar.gz (29.4 kB view details)

Uploaded Source

Built Distribution

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

live_cells_py-0.2.0-py3-none-any.whl (29.2 kB view details)

Uploaded Python 3

File details

Details for the file live_cells_py-0.2.0.tar.gz.

File metadata

  • Download URL: live_cells_py-0.2.0.tar.gz
  • Upload date:
  • Size: 29.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.1

File hashes

Hashes for live_cells_py-0.2.0.tar.gz
Algorithm Hash digest
SHA256 77985f41de0aa79aa24eadc4cdc4cd506a5db27455939333f6d7460c8654f1da
MD5 0283a8be5759f003a828ad599856316d
BLAKE2b-256 dc367e2908b9306bbebf14176744862bb8bfeb98d36055ce0f7bf63a8b07c60a

See more details on using hashes here.

File details

Details for the file live_cells_py-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: live_cells_py-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 29.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.1

File hashes

Hashes for live_cells_py-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bd0e9566e1ecbc65cd64caae7ca7536e458ecf07bd066ada96d0c4973a471b2d
MD5 59f8d727c008c36a6b154dcd6e2d9503
BLAKE2b-256 ecf170329876211612d68a9d05210d641eb95916aaf3779ea3b0ffc658afbe8e

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