Skip to content

Commit

Permalink
Merge pull request #18 from gabrielguarisa/f/connectors
Browse files Browse the repository at this point in the history
Connector Node
  • Loading branch information
gabrielguarisa authored Dec 11, 2023
2 parents d872233 + 0548724 commit 3b69b42
Show file tree
Hide file tree
Showing 33 changed files with 1,343 additions and 990 deletions.
4 changes: 1 addition & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,9 @@ This will run the tests with [pytest](https://docs.pytest.org/en/latest/) and sh
To format the code, you can use the command:

```bash
make formatting
make linting
```

This will run the [isort](https://github.com/PyCQA/isort) and [black](https://github.com/psf/black) commands.

### Releasing a new version

To release a new version, you need to follow these steps:
Expand Down
3 changes: 3 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ formatting:
check-formatting:
poetry run ruff check .

.PHONY: linting
linting: formatting check-formatting

.PHONY: tests
tests:
poetry run pytest | tee pytest-coverage.txt
29 changes: 5 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,11 @@ pip install retrack
```python
import retrack

runner = retrack.Runner.from_json("your-rule.json")
rule = retrack.from_json("rule.json")

response = runner.execute(input_data)
result = rule.execute(your_data_df)
```

Or, if you want to create the parser and runner manually:

```python
import retrack

# Parse the rule/model
parser = retrack.Parser(rule)

# Create a runner
runner = retrack.Runner(parser, name="your-rule")

# Run the rule/model passing the data
runner.execute(data)
```

The `Parser` class parses the rule/model and creates a graph of nodes. The `Runner` class runs the rule/model using the data passed to the runner. The `data` is a dictionary or a list of dictionaries containing the data that will be used to evaluate the conditions and execute the actions. To see wich data is required for the given rule/model, check the `runner.request_model` property that is a pydantic model used to validate the data.

Optionally you can name the rule by passing the `name` field to the `retrack.Runner` constructor. This is useful to identify the rule when exceptions are raised.

### 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.
Expand Down Expand Up @@ -130,10 +111,10 @@ After creating the custom node, you need to register it in the nodes registry an
import retrack

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

# Parse the rule/model
parser = Parser(rule, component_registry=retrack.component_registry)
rule = retrack.from_json("rule.json", nodes_registry=custom_registry)
```

## Contributing
Expand Down
296 changes: 0 additions & 296 deletions examples/age-check.json

This file was deleted.

24 changes: 0 additions & 24 deletions examples/age_check.py

This file was deleted.

Loading

0 comments on commit 3b69b42

Please sign in to comment.