retrack


Nameretrack JSON
Version 2.5.0 PyPI version JSON
download
home_pagehttps://github.com/pier-digital/retrack
SummaryA business rules engine
upload_time2024-04-02 14:21:59
maintainerNone
docs_urlNone
authorGabriel Guarisa
requires_python<4.0.0,>=3.9
licenseMIT
keywords rules models business node graph
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <p align="center">
  <a href="https://github.com/pier-digital/retrack"><img src="https://raw.githubusercontent.com/pier-digital/retrack/main/logo.png" alt="retrack"></a>
</p>
<p align="center">
    <em>A business rules engine</em>
</p>

<div align="center">

[![Package version](https://img.shields.io/pypi/v/retrack?color=%2334D058&label=pypi%20package)](https://pypi.org/project/retrack/)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)
[![Semantic Versions](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--versions-e10079.svg)](https://github.com/pier-digital/retrack/releases)
[![License](https://img.shields.io/github/license/pier-digital/retrack)](https://github.com/pier-digital/retrack/blob/main/LICENSE)

</div>


## Installation

```bash
pip install retrack
```

## Usage

```python
import retrack

rule = retrack.from_json("rule.json")

result = rule.execute(your_data_df)
```

### Creating a rule/model

A rule is a set of conditions and actions that are executed when the conditions are met. The conditions are evaluated using the data passed to the runner. The actions are executed when the conditions are met.

Each rule is composed of many nodes. To see each node type, check the [nodes](https://github.com/pier-digital/retrack/tree/main/retrack/nodes) folder.

To create a rule, you need to create a JSON file with the following structure:

```json
{
  "nodes": {
		"node id": {
			"id": "node id",
			"data": {},
			"inputs": {},
			"outputs": {},
			"name": "node name",
		},
    // ... more nodes
  }
}
```

The `nodes` key is a dictionary of nodes. Each node has the following properties:

- `id`: The node id. This is used to reference the node in the `inputs` and `outputs` properties.
- `data`: The node data. This is used as a metadata for the node.
- `inputs`: The node inputs. This is used to reference the node inputs.
- `outputs`: The node outputs. This is used to reference the node outputs.
- `name`: The node name. This is used to define the node type.

The `inputs` and `outputs` properties are dictionaries of node connections. Each connection has the following properties:

- `node`: The node id that is connected to the current node.
- `input`: The input name of the connection that is connected to the current node. This is only used in the `inputs` property.
- `output`: The output name of the connection that is connected to the current node. This is only used in the `outputs` property.

To see some examples, check the [examples](https://github.com/pier-digital/retrack/tree/main/examples) folder.

### Creating a custom node

To create a custom node, you need to create a class that inherits from the `BaseNode` class. Each node is a pydantic model, so you can use pydantic features to create your custom node. To see the available features, check the [pydantic documentation](https://pydantic-docs.helpmanual.io/).

To create a custom node you need to define the inputs and outputs of the node. To do this, you need to define the `inputs` and `outputs` class attributes. Let's see an example of a custom node that has two inputs, sum them and return the result:

```python
import retrack
import pydantic
import pandas as pd
import typing


class SumInputsModel(pydantic.BaseModel):
    input_value_0: retrack.InputConnectionModel
    input_value_1: retrack.InputConnectionModel


class SumOutputsModel(pydantic.BaseModel):
    output_value: retrack.OutputConnectionModel


class SumNode(retrack.BaseNode):
    inputs: SumInputsModel
    outputs: SumOutputsModel

    def run(self, input_value_0: pd.Series,
        input_value_1: pd.Series,
    ) -> typing.Dict[str, pd.Series]:
        output_value = input_value_0.astype(float) + input_value_1.astype(float)
        return {
            "output_value": output_value,
        }
```

After creating the custom node, you need to register it in the nodes registry and pass the registry to the parser. Let's see an example:

```python
import retrack

# Register the custom node
custom_registry = retrack.nodes_registry()
custom_registry.register("sum", SumNode)

rule = retrack.from_json("rule.json", nodes_registry=custom_registry)
```

## Contributing

Contributions are welcome! Please read the [contributing guidelines](https://github.com/pier-digital/retrack/tree/main/CONTRIBUTING.md) first.
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/pier-digital/retrack",
    "name": "retrack",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0.0,>=3.9",
    "maintainer_email": null,
    "keywords": "rules, models, business, node, graph",
    "author": "Gabriel Guarisa",
    "author_email": "gabriel.guarisa@pier.digital",
    "download_url": "https://files.pythonhosted.org/packages/c1/e3/1bf915d6e319e598c5811716cc78a198b5d037e9d577472d8e78e1b7f6f3/retrack-2.5.0.tar.gz",
    "platform": null,
    "description": "<p align=\"center\">\n  <a href=\"https://github.com/pier-digital/retrack\"><img src=\"https://raw.githubusercontent.com/pier-digital/retrack/main/logo.png\" alt=\"retrack\"></a>\n</p>\n<p align=\"center\">\n    <em>A business rules engine</em>\n</p>\n\n<div align=\"center\">\n\n[![Package version](https://img.shields.io/pypi/v/retrack?color=%2334D058&label=pypi%20package)](https://pypi.org/project/retrack/)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n[![Semantic Versions](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--versions-e10079.svg)](https://github.com/pier-digital/retrack/releases)\n[![License](https://img.shields.io/github/license/pier-digital/retrack)](https://github.com/pier-digital/retrack/blob/main/LICENSE)\n\n</div>\n\n\n## Installation\n\n```bash\npip install retrack\n```\n\n## Usage\n\n```python\nimport retrack\n\nrule = retrack.from_json(\"rule.json\")\n\nresult = rule.execute(your_data_df)\n```\n\n### Creating a rule/model\n\nA rule is a set of conditions and actions that are executed when the conditions are met. The conditions are evaluated using the data passed to the runner. The actions are executed when the conditions are met.\n\nEach rule is composed of many nodes. To see each node type, check the [nodes](https://github.com/pier-digital/retrack/tree/main/retrack/nodes) folder.\n\nTo create a rule, you need to create a JSON file with the following structure:\n\n```json\n{\n  \"nodes\": {\n\t\t\"node id\": {\n\t\t\t\"id\": \"node id\",\n\t\t\t\"data\": {},\n\t\t\t\"inputs\": {},\n\t\t\t\"outputs\": {},\n\t\t\t\"name\": \"node name\",\n\t\t},\n    // ... more nodes\n  }\n}\n```\n\nThe `nodes` key is a dictionary of nodes. Each node has the following properties:\n\n- `id`: The node id. This is used to reference the node in the `inputs` and `outputs` properties.\n- `data`: The node data. This is used as a metadata for the node.\n- `inputs`: The node inputs. This is used to reference the node inputs.\n- `outputs`: The node outputs. This is used to reference the node outputs.\n- `name`: The node name. This is used to define the node type.\n\nThe `inputs` and `outputs` properties are dictionaries of node connections. Each connection has the following properties:\n\n- `node`: The node id that is connected to the current node.\n- `input`: The input name of the connection that is connected to the current node. This is only used in the `inputs` property.\n- `output`: The output name of the connection that is connected to the current node. This is only used in the `outputs` property.\n\nTo see some examples, check the [examples](https://github.com/pier-digital/retrack/tree/main/examples) folder.\n\n### Creating a custom node\n\nTo create a custom node, you need to create a class that inherits from the `BaseNode` class. Each node is a pydantic model, so you can use pydantic features to create your custom node. To see the available features, check the [pydantic documentation](https://pydantic-docs.helpmanual.io/).\n\nTo create a custom node you need to define the inputs and outputs of the node. To do this, you need to define the `inputs` and `outputs` class attributes. Let's see an example of a custom node that has two inputs, sum them and return the result:\n\n```python\nimport retrack\nimport pydantic\nimport pandas as pd\nimport typing\n\n\nclass SumInputsModel(pydantic.BaseModel):\n    input_value_0: retrack.InputConnectionModel\n    input_value_1: retrack.InputConnectionModel\n\n\nclass SumOutputsModel(pydantic.BaseModel):\n    output_value: retrack.OutputConnectionModel\n\n\nclass SumNode(retrack.BaseNode):\n    inputs: SumInputsModel\n    outputs: SumOutputsModel\n\n    def run(self, input_value_0: pd.Series,\n        input_value_1: pd.Series,\n    ) -> typing.Dict[str, pd.Series]:\n        output_value = input_value_0.astype(float) + input_value_1.astype(float)\n        return {\n            \"output_value\": output_value,\n        }\n```\n\nAfter creating the custom node, you need to register it in the nodes registry and pass the registry to the parser. Let's see an example:\n\n```python\nimport retrack\n\n# Register the custom node\ncustom_registry = retrack.nodes_registry()\ncustom_registry.register(\"sum\", SumNode)\n\nrule = retrack.from_json(\"rule.json\", nodes_registry=custom_registry)\n```\n\n## Contributing\n\nContributions are welcome! Please read the [contributing guidelines](https://github.com/pier-digital/retrack/tree/main/CONTRIBUTING.md) first.",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "A business rules engine",
    "version": "2.5.0",
    "project_urls": {
        "Homepage": "https://github.com/pier-digital/retrack",
        "Repository": "https://github.com/pier-digital/retrack"
    },
    "split_keywords": [
        "rules",
        " models",
        " business",
        " node",
        " graph"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f4c5cc079d3c6d5394258b9564bdcb867a12b48dbfa9d1caa07acc3782bab6b2",
                "md5": "0b5a4509ebf0edb44de17a5961cc6057",
                "sha256": "f32cde493331c6208ebce0ad88d5ca0e6493121d42d0ed3f1f9f6ab6ad45cf03"
            },
            "downloads": -1,
            "filename": "retrack-2.5.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0b5a4509ebf0edb44de17a5961cc6057",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0.0,>=3.9",
            "size": 31907,
            "upload_time": "2024-04-02T14:21:57",
            "upload_time_iso_8601": "2024-04-02T14:21:57.843802Z",
            "url": "https://files.pythonhosted.org/packages/f4/c5/cc079d3c6d5394258b9564bdcb867a12b48dbfa9d1caa07acc3782bab6b2/retrack-2.5.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c1e31bf915d6e319e598c5811716cc78a198b5d037e9d577472d8e78e1b7f6f3",
                "md5": "05346284be63e82dfa389a63f1a89c90",
                "sha256": "cca823fc25e7be06bc4db4fa6bdc39fa9c16eddd43c692fa0dfb2a06afa3ed93"
            },
            "downloads": -1,
            "filename": "retrack-2.5.0.tar.gz",
            "has_sig": false,
            "md5_digest": "05346284be63e82dfa389a63f1a89c90",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0.0,>=3.9",
            "size": 19821,
            "upload_time": "2024-04-02T14:21:59",
            "upload_time_iso_8601": "2024-04-02T14:21:59.210564Z",
            "url": "https://files.pythonhosted.org/packages/c1/e3/1bf915d6e319e598c5811716cc78a198b5d037e9d577472d8e78e1b7f6f3/retrack-2.5.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-02 14:21:59",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pier-digital",
    "github_project": "retrack",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "retrack"
}
        
Elapsed time: 0.21686s