posted


Nameposted JSON
Version 0.1.4 PyPI version JSON
download
home_pagehttps://github.com/i2mint/posted
SummaryInterfacing with message-broker functionality
upload_time2024-03-18 08:28:56
maintainer
docs_urlNone
authorOtoSense
requires_python
licensemit
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# posted
Interfacing with message-broker functionality


To install:	```pip install posted```


# Examples

## ReactiveScope

A scope that reacts to writes by computing associated functions, themselves writing in the scope, creating a chain reaction that propagates information through the scope.

Parameters
----------

* `func_nodes : Iterable[ReactiveFuncNode]`
    The functions that will be called when the scope is written to.
* `scope_factory : Callable[[], MutableMapping]`
    A factory that returns a new scope. The scope will be cleared by calling this
    factory at each call to `.clear()`.

Examples
--------

First, we need some func nodes to define the reaction relationships.
We'll stuff these func nodes in a DAG, for ease of use, but it's not necessary.

```python
>>> from meshed import FuncNode, DAG
>>>
>>> def f(a, b):
...     return a + b
>>> def g(a_plus_b, d):
...     return a_plus_b * d
>>> f_node = FuncNode(func=f, out='a_plus_b')
>>> g_node = FuncNode(func=g, bind={'d': 'b'})
>>> d = DAG((f_node, g_node))
>>>
>>> print(d.dot_digraph_ascii())
<BLANKLINE>
                a
<BLANKLINE>
            │
            │
            ▼
            ┌────────┐
    b   ──▶ │   f    │
            └────────┘
    │         │
    │         │
    │         ▼
    │
    │        a_plus_b
    │
    │         │
    │         │
    │         ▼
    │       ┌────────┐
    └─────▶ │   g_   │
            └────────┘
            │
            │
            ▼
<BLANKLINE>
                g
<BLANKLINE>
```

Now we make a scope with these func nodes.

```python
>>> s = ReactiveScope(d)
```

The scope starts empty (by default).

```python
>>> s
<ReactiveScope with .scope: {}>
```

So if we try to access any key, we'll get a KeyError.

```python
>>> s['g']  # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
    ...
KeyError: 'g'
```

That's because we didn't put write anything in the scope yet.

But, if you give ``g_`` enough data to be able to compute ``g`` (namely, if you
write values of ``b`` and ``a_plus_b``), then ``g`` will automatically be computed.

```python
>>> s['b'] = 3
>>> s['a_plus_b'] = 5
>>> s
<ReactiveScope with .scope: {'b': 3, 'a_plus_b': 5, 'g': 15}>
```

So now we can access ``g``.

```python
>>> s['g']
15
```

Note though, that we first showed that ``g`` appeared in the scope before we
explicitly asked for it. This was to show that ``g`` was computed as a
side-effect of writing to the scope, not because we asked for it, triggering the
computation

Let's clear the scope and show that by specifying ``a`` and ``b``, we get all the
other values of the network.

```python
>>> s.clear()
>>> s
<ReactiveScope with .scope: {}>
>>> s['a'] = 3
>>> s['b'] = 4
>>> s
<ReactiveScope with .scope: {'a': 3, 'b': 4, 'a_plus_b': 7, 'g': 28}>
>>> s['g']  # (3 + 4) * 4 == 7 * 4 == 28
28
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/i2mint/posted",
    "name": "posted",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "",
    "author": "OtoSense",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/2d/70/433be5925f1dc975d9030dcb0b9ec87327e7ad2577b913ec44fa5596314b/posted-0.1.4.tar.gz",
    "platform": "any",
    "description": "\n# posted\nInterfacing with message-broker functionality\n\n\nTo install:\t```pip install posted```\n\n\n# Examples\n\n## ReactiveScope\n\nA scope that reacts to writes by computing associated functions, themselves writing in the scope, creating a chain reaction that propagates information through the scope.\n\nParameters\n----------\n\n* `func_nodes : Iterable[ReactiveFuncNode]`\n    The functions that will be called when the scope is written to.\n* `scope_factory : Callable[[], MutableMapping]`\n    A factory that returns a new scope. The scope will be cleared by calling this\n    factory at each call to `.clear()`.\n\nExamples\n--------\n\nFirst, we need some func nodes to define the reaction relationships.\nWe'll stuff these func nodes in a DAG, for ease of use, but it's not necessary.\n\n```python\n>>> from meshed import FuncNode, DAG\n>>>\n>>> def f(a, b):\n...     return a + b\n>>> def g(a_plus_b, d):\n...     return a_plus_b * d\n>>> f_node = FuncNode(func=f, out='a_plus_b')\n>>> g_node = FuncNode(func=g, bind={'d': 'b'})\n>>> d = DAG((f_node, g_node))\n>>>\n>>> print(d.dot_digraph_ascii())\n<BLANKLINE>\n                a\n<BLANKLINE>\n            \u2502\n            \u2502\n            \u25bc\n            \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n    b   \u2500\u2500\u25b6 \u2502   f    \u2502\n            \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n    \u2502         \u2502\n    \u2502         \u2502\n    \u2502         \u25bc\n    \u2502\n    \u2502        a_plus_b\n    \u2502\n    \u2502         \u2502\n    \u2502         \u2502\n    \u2502         \u25bc\n    \u2502       \u250c\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2510\n    \u2514\u2500\u2500\u2500\u2500\u2500\u25b6 \u2502   g_   \u2502\n            \u2514\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2500\u2518\n            \u2502\n            \u2502\n            \u25bc\n<BLANKLINE>\n                g\n<BLANKLINE>\n```\n\nNow we make a scope with these func nodes.\n\n```python\n>>> s = ReactiveScope(d)\n```\n\nThe scope starts empty (by default).\n\n```python\n>>> s\n<ReactiveScope with .scope: {}>\n```\n\nSo if we try to access any key, we'll get a KeyError.\n\n```python\n>>> s['g']  # doctest: +IGNORE_EXCEPTION_DETAIL\nTraceback (most recent call last):\n    ...\nKeyError: 'g'\n```\n\nThat's because we didn't put write anything in the scope yet.\n\nBut, if you give ``g_`` enough data to be able to compute ``g`` (namely, if you\nwrite values of ``b`` and ``a_plus_b``), then ``g`` will automatically be computed.\n\n```python\n>>> s['b'] = 3\n>>> s['a_plus_b'] = 5\n>>> s\n<ReactiveScope with .scope: {'b': 3, 'a_plus_b': 5, 'g': 15}>\n```\n\nSo now we can access ``g``.\n\n```python\n>>> s['g']\n15\n```\n\nNote though, that we first showed that ``g`` appeared in the scope before we\nexplicitly asked for it. This was to show that ``g`` was computed as a\nside-effect of writing to the scope, not because we asked for it, triggering the\ncomputation\n\nLet's clear the scope and show that by specifying ``a`` and ``b``, we get all the\nother values of the network.\n\n```python\n>>> s.clear()\n>>> s\n<ReactiveScope with .scope: {}>\n>>> s['a'] = 3\n>>> s['b'] = 4\n>>> s\n<ReactiveScope with .scope: {'a': 3, 'b': 4, 'a_plus_b': 7, 'g': 28}>\n>>> s['g']  # (3 + 4) * 4 == 7 * 4 == 28\n28\n```\n",
    "bugtrack_url": null,
    "license": "mit",
    "summary": "Interfacing with message-broker functionality",
    "version": "0.1.4",
    "project_urls": {
        "Homepage": "https://github.com/i2mint/posted"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c06c2fb1fc540c56567ce5aa3f64b73e266f229a32e8627fd76151af63f462a4",
                "md5": "5f7f717cee4e643a7d9e9ba67260bd87",
                "sha256": "d52f2f3bad506c9058f3670b63b8bd009d878e300fbd2892c63683edd7017a7e"
            },
            "downloads": -1,
            "filename": "posted-0.1.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5f7f717cee4e643a7d9e9ba67260bd87",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 8921,
            "upload_time": "2024-03-18T08:28:55",
            "upload_time_iso_8601": "2024-03-18T08:28:55.310919Z",
            "url": "https://files.pythonhosted.org/packages/c0/6c/2fb1fc540c56567ce5aa3f64b73e266f229a32e8627fd76151af63f462a4/posted-0.1.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "2d70433be5925f1dc975d9030dcb0b9ec87327e7ad2577b913ec44fa5596314b",
                "md5": "49473eb110c218cd6dcdb2f30f7d7fb1",
                "sha256": "6b0f187c2c46b52e58010ba6a2eaee159f411b37e8da8fcb817dac77dcb77baf"
            },
            "downloads": -1,
            "filename": "posted-0.1.4.tar.gz",
            "has_sig": false,
            "md5_digest": "49473eb110c218cd6dcdb2f30f7d7fb1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 7491,
            "upload_time": "2024-03-18T08:28:56",
            "upload_time_iso_8601": "2024-03-18T08:28:56.871623Z",
            "url": "https://files.pythonhosted.org/packages/2d/70/433be5925f1dc975d9030dcb0b9ec87327e7ad2577b913ec44fa5596314b/posted-0.1.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-03-18 08:28:56",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "i2mint",
    "github_project": "posted",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "posted"
}
        
Elapsed time: 0.63896s