Skip to main content

A Python Rules Engine - Make rule handling simple

Project description

Arta

Make rule handling simple

CI Coverage Versions Python Python implementation Downloads


Documentation: https://maif.github.io/arta/home/

Repository: https://github.com/MAIF/arta


Overview

Arta is an open source python rules engine designed for and by python developers.

Goal

There is one main reason for using Arta and it was the main goal behind its development at MAIF: increase business rules maintainability.

In other words, facilitate rules handling in our python apps.

Origins

The need of a python rules engine emerged when we were working on a new major release of our internal use of Melusine (i.e., email qualification pipeline with ML capabilities).

We were looking for a python library to centralize, manage and standardize all the implemented business rules we had but didn't find the perfect fit.

Therefore, we decided to create this package and by extension of the MAIF's values, we planned to share it to the community.

Features

  • Standardize the definition of a rule. All rules are defined the same way in a unique place.
  • Rules are released from the code base, which is less error prone and increases clearness.
  • Use Arta whatever your field is.
  • Great combination with Machine Learning: groups all the deterministic rules of your ML projects.

A Simple Example

Create the three following files and run the main.py script (python main.py or python3 main.py).

rules.yaml :

---
rules:
  default_rule_set:
    admission:
      ADMITTED:
        simple_condition: input.power=="strength" or input.power=="fly"
        action: set_admission
        action_parameters:
          value: true  
      NOT_ADMITTED:
        simple_condition: null
        action: set_admission
        action_parameters:
          value: false

actions_source_modules:
  - actions

actions.py :

from typing import Any


def set_admission(value: bool, **kwargs: Any) -> dict[str, bool]:
    """Return a dictionary containing the admission result."""
    return {"is_admitted": value}

main.py :

from arta import RulesEngine

eng = RulesEngine(config_path=".")

data = {
        "id": 1,
        "name": "Superman",
        "civilian_name": "Clark Kent",
        "age": None,
        "city": "Metropolis",
        "language": "english",
        "power": "fly",
        "favorite_meal": "Spinach",
        "secret_weakness": "Kryptonite",
        }

result = eng.apply_rules(input_data=data)

print(result)

You should get: {"admission": {"is_admitted": True}}

Check the A Simple Example section for more details.

Installation

Install using pip install -U:

pip install -U arta

See the Install section in the documentation for more details.

What's New

Want to see last updates, check the Release Notes or the Changelog.

Community

You can discuss and ask Arta related questions:

  • Issue tracker: github: MAIF/arta/issues
  • Pull request: github: MAIF/arta/pulls

Contributing

Contributions are very welcome!

If you see an issue that you'd like to see fixed, the best way to make it happen is to help out by submitting a pull request implementing it.

Refer to the CONTRIBUTING.md file for more details about the workflow, and general hints on how to prepare your pull request. You can also ask for clarifications or guidance in GitHub issues directly.

License

This project is Open Source and available under the Apache 2 License.

Alt MAIF Logo

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

arta-0.9.0.tar.gz (21.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

arta-0.9.0-py3-none-any.whl (21.8 kB view details)

Uploaded Python 3

File details

Details for the file arta-0.9.0.tar.gz.

File metadata

  • Download URL: arta-0.9.0.tar.gz
  • Upload date:
  • Size: 21.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for arta-0.9.0.tar.gz
Algorithm Hash digest
SHA256 99f736aa53436d9dc3e00c4d33701bd4611a5ff9c38e720c36cf11e4701f6f40
MD5 b68b8cbcfb682cd4a2cfc690bb4fd2a2
BLAKE2b-256 e3ead827dc88ac9d07eb7eecefb5cd85e2141a0fc748386a4d108514f1a2d004

See more details on using hashes here.

Provenance

The following attestation bundles were made for arta-0.9.0.tar.gz:

Publisher: ci-cd.yml on MAIF/arta

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file arta-0.9.0-py3-none-any.whl.

File metadata

  • Download URL: arta-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 21.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for arta-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c22dffdd9260db570e448e72121a1429fde392a936810fc7e37c345b0d2a1ee6
MD5 a22798e57d27a2a467962b9cd7b302f9
BLAKE2b-256 dbc86759a1ad490465d8a38a2756ee7210aa0ad0ba0316a95699fa3da98f751e

See more details on using hashes here.

Provenance

The following attestation bundles were made for arta-0.9.0-py3-none-any.whl:

Publisher: ci-cd.yml on MAIF/arta

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page