Name | grafo JSON |
Version |
0.2.17
JSON |
| download |
home_page | None |
Summary | A library for building runnable asynchronous trees |
upload_time | 2025-07-14 17:56:40 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.6 |
license | MIT |
keywords |
asynchronous
trees
library
|
VCS |
 |
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
## What ##
A simple library for building runnable async trees. Trees are a web of interconnected Nodes, which contain code to be run. The number of workers is automatically managed (optional).
## Use
**Building a tree with the `|` operator**
```python
# Declare your nodes
root_node = Node(...)
child1 = Node(...)
child2 = Node(...)
grandchild = Node(...)
# Set the layout
nodes = {
root_node: {
child1: [grandchild],
child2: [grandchild], # grandchild_node will wait for child1 and child2 to complete before running
}
}
# Use the '|' operator to connect the nodes
executor = AsyncTreeExecutor(logger=logger)
tree = executor | nodes
result = await tree.run()
```
**Connecting nodes manually**
```python
root_node = Node(...)
child1 = Node(...)
await root_node.connect(child1)
```
**Evaluating coroutine kwargs during runtime**
```python
node = Node(
coroutine=my_coroutine
kwargs=dict(
my_arg=lambda: my_arg
)
)
```
**Altering a tree during runtime**
updated example coming later
Powered by `asyncio` (https://docs.python.org/3/library/asyncio.html)
## How ##
- You have a tree of interconected `Nodes` and an `asyncio.Queue()`
- Upon each Node's execution, it removes itself from the queue and enqueues its children up next
## Axioms ##
1) Children start running as soon as all their parent's are finished.
2) There's no passing of state between nodes - you can handle that however you see fit
## Important ##
- Node properties are generally accessible, but are immutable during a node's runtime (do not confuse with the tree's runtime).
- Coroutines and callbacks will always receive the `node` as their first (positional) argument. Everything else if a `keyword argument`.
- `on_before_run` and `on_after_run` callbacks must be asynchronous
## Installation ##
- `pip install grafo` to install on your environment
- `pytest` to run tests, add `-s` flag for tests to run `print` statements
## Zen ##
1. Follow established names: a Node is a Node, not a "Leaf".
2. Syntax sugar is sweet in moderation.
3. Give the programmer granular control.
Raw data
{
"_id": null,
"home_page": null,
"name": "grafo",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": null,
"keywords": "asynchronous, trees, library",
"author": null,
"author_email": "\"@paulomtts\" <paulomtts@outlook.com>",
"download_url": "https://files.pythonhosted.org/packages/a7/6f/b9a2d41bd3180e19d421850ef1713efde383c519d16c8cc2b76fc44f37b6/grafo-0.2.17.tar.gz",
"platform": null,
"description": "## What ##\nA simple library for building runnable async trees. Trees are a web of interconnected Nodes, which contain code to be run. The number of workers is automatically managed (optional).\n\n## Use\n\n**Building a tree with the `|` operator**\n```python\n# Declare your nodes\nroot_node = Node(...)\nchild1 = Node(...)\nchild2 = Node(...)\ngrandchild = Node(...)\n\n# Set the layout\nnodes = {\n root_node: {\n child1: [grandchild],\n child2: [grandchild], # grandchild_node will wait for child1 and child2 to complete before running\n }\n}\n\n# Use the '|' operator to connect the nodes\nexecutor = AsyncTreeExecutor(logger=logger)\ntree = executor | nodes\nresult = await tree.run()\n```\n\n**Connecting nodes manually**\n```python\nroot_node = Node(...)\nchild1 = Node(...)\n\nawait root_node.connect(child1)\n```\n\n\n**Evaluating coroutine kwargs during runtime**\n```python\nnode = Node(\n coroutine=my_coroutine\n kwargs=dict(\n my_arg=lambda: my_arg\n )\n)\n```\n\n**Altering a tree during runtime**\nupdated example coming later\n\nPowered by `asyncio` (https://docs.python.org/3/library/asyncio.html)\n\n## How ##\n- You have a tree of interconected `Nodes` and an `asyncio.Queue()`\n- Upon each Node's execution, it removes itself from the queue and enqueues its children up next\n\n## Axioms ##\n1) Children start running as soon as all their parent's are finished.\n2) There's no passing of state between nodes - you can handle that however you see fit\n\n## Important ##\n- Node properties are generally accessible, but are immutable during a node's runtime (do not confuse with the tree's runtime).\n- Coroutines and callbacks will always receive the `node` as their first (positional) argument. Everything else if a `keyword argument`.\n- `on_before_run` and `on_after_run` callbacks must be asynchronous\n\n## Installation ##\n- `pip install grafo` to install on your environment\n- `pytest` to run tests, add `-s` flag for tests to run `print` statements\n\n## Zen ##\n1. Follow established names: a Node is a Node, not a \"Leaf\".\n2. Syntax sugar is sweet in moderation.\n3. Give the programmer granular control.\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A library for building runnable asynchronous trees",
"version": "0.2.17",
"project_urls": {
"Homepage": "https://github.com/HappyLoop/grafo"
},
"split_keywords": [
"asynchronous",
" trees",
" library"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "cb1b3791e594a13d0f879bcdefbfbee31cadcdb436982c99387c4d6f36d64785",
"md5": "58c8c3dbea0d92590cb3e7b4ef291617",
"sha256": "c60b8e976c00bf580258e29ef793fdc13be97b5d95cec3d3bc020daf85b99c5c"
},
"downloads": -1,
"filename": "grafo-0.2.17-py3-none-any.whl",
"has_sig": false,
"md5_digest": "58c8c3dbea0d92590cb3e7b4ef291617",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6",
"size": 10228,
"upload_time": "2025-07-14T17:56:39",
"upload_time_iso_8601": "2025-07-14T17:56:39.702249Z",
"url": "https://files.pythonhosted.org/packages/cb/1b/3791e594a13d0f879bcdefbfbee31cadcdb436982c99387c4d6f36d64785/grafo-0.2.17-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "a76fb9a2d41bd3180e19d421850ef1713efde383c519d16c8cc2b76fc44f37b6",
"md5": "67387f28f608873b8f1a41e6a9878497",
"sha256": "3ef0f6f63d7fdecfcc0c903f12ced05162b3292fbf8e2be5f20cf7b183b17cc3"
},
"downloads": -1,
"filename": "grafo-0.2.17.tar.gz",
"has_sig": false,
"md5_digest": "67387f28f608873b8f1a41e6a9878497",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 12961,
"upload_time": "2025-07-14T17:56:40",
"upload_time_iso_8601": "2025-07-14T17:56:40.601645Z",
"url": "https://files.pythonhosted.org/packages/a7/6f/b9a2d41bd3180e19d421850ef1713efde383c519d16c8cc2b76fc44f37b6/grafo-0.2.17.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-14 17:56:40",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "HappyLoop",
"github_project": "grafo",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "grafo"
}