grafo


Namegrafo JSON
Version 0.2.36 PyPI version JSON
download
home_pageNone
SummaryA library for building runnable asynchronous trees
upload_time2025-07-31 01:31:01
maintainerNone
docs_urlNone
authorNone
requires_python>=3.6
licenseMIT
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 = TreeExecutor(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.
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/1a/87/06886031165f825b75333877a02c589743c95f2d9736b8afda66c8c2f2f0/grafo-0.2.36.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 = TreeExecutor(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.\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.36",
    "project_urls": {
        "Homepage": "https://github.com/HappyLoop/grafo"
    },
    "split_keywords": [
        "asynchronous",
        " trees",
        " library"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "f5ee07019094b6856802519cebcce7acf505be3cb82f14440cdd2d62c2b90df5",
                "md5": "b38154db428de0a818e7aa580b933590",
                "sha256": "fce85ccb7ce5e29fb239dd9580b810d4b370ce9f472e94975f918113e8bd84e0"
            },
            "downloads": -1,
            "filename": "grafo-0.2.36-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b38154db428de0a818e7aa580b933590",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 11186,
            "upload_time": "2025-07-31T01:31:00",
            "upload_time_iso_8601": "2025-07-31T01:31:00.700182Z",
            "url": "https://files.pythonhosted.org/packages/f5/ee/07019094b6856802519cebcce7acf505be3cb82f14440cdd2d62c2b90df5/grafo-0.2.36-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "1a8706886031165f825b75333877a02c589743c95f2d9736b8afda66c8c2f2f0",
                "md5": "046c4bd65724c9bcc8cbd2eb5d06d148",
                "sha256": "28548f73736bfdffdcbd96134b3aefc9010c80c06cffd4a75dad3256883e7a41"
            },
            "downloads": -1,
            "filename": "grafo-0.2.36.tar.gz",
            "has_sig": false,
            "md5_digest": "046c4bd65724c9bcc8cbd2eb5d06d148",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 16327,
            "upload_time": "2025-07-31T01:31:01",
            "upload_time_iso_8601": "2025-07-31T01:31:01.833214Z",
            "url": "https://files.pythonhosted.org/packages/1a/87/06886031165f825b75333877a02c589743c95f2d9736b8afda66c8c2f2f0/grafo-0.2.36.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-31 01:31:01",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "HappyLoop",
    "github_project": "grafo",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "grafo"
}
        
Elapsed time: 0.57570s