Welcome to larch.reactive’s documentation!¶
larch.reactive is a reactive programming library for python. The objectives of larch.reactive were:
to be lean
to be fast
compatible (it should be possible to add reactive behaviour to existing classes)
provide a consistent programming model.
debuggable
Lets start with an example to demonstrate how larch.reactive works:
>>> import larch.reactive as ra
>>> from datetime import datetime, timedelta
>>>
>>> @ra.reactive
... class Task(object):
... start = ra.Cell(datetime.now())
... end = ra.Cell()
... duration = ra.Cell(timedelta(hours=3))
... prev = ra.Cell()
... desc = ra.Cell("")
...
... @ra.rule
... def _rule_start(self):
... if self.prev:
... self.start = self.prev.end
...
... @ra.rule
... def _rule_end(self):
... self.end = self.start + self.duration
...
... def __repr__(self):
... return "'{}': {} -> {}".format(self.desc, self.start, self.end)
...
>>> read = Task(desc="read tutorial", start=datetime(2016, 1, 9, 8),
... duration=timedelta(hours=2))
>>> read
'read tutorial': 2016-01-09 08:00:00 -> 2016-01-09 10:00:00
>>> write = Task(desc="write own programs", prev=read)
>>> write
'write own programs': 2016-01-09 10:00:00 -> 2016-01-09 13:00:00
>>> read.duration = timedelta(hours=3)
>>> read
'read tutorial': 2016-01-09 08:00:00 -> 2016-01-09 11:00:00
>>> write
'write own programs': 2016-01-09 11:00:00 -> 2016-01-09 14:00:00
A reactive class has cell attributes and rules that are called whenever a cell has changed. For a more detailed discussion see the first use case.
Installation¶
Install larch.reactive, either from a distribution package or from PyPI with
$ pip install larch-reactive
License¶
larch.reactive is released under LGPL licence.