Skip to main content

This project provides a library for creating general purpose "Rule" objects from a logical expression which can then be applied to arbitrary objects to evaluate whether or not they match.

Project description

This project provides a library for creating general purpose “Rule” objects from a logical expression which can then be applied to arbitrary objects to evaluate whether or not they match.

Documentation is available at https://zeroSteiner.github.io/rule-engine/.

Rule Engine expressions are written in their own language, defined as strings in Python. Some features of this language includes:

  • Optional type hinting

  • Matching strings with regular expressions

  • Datetime datatypes

  • Data attributes

Example

The following example demonstrates the basic usage of defining a rule object and applying it to two dictionaries, showing that one matches while the other does not. See Getting Started for more information.

import rule_engine
# match a literal first name and applying a regex to the email
rule = rule_engine.Rule(
    'first_name == "Luke" and email =~ ".*@rebels.org$"'
) # => <Rule text='first_name == "Luke" and email =~ ".*@rebels.org$"' >
rule.matches({
    'first_name': 'Luke', 'last_name': 'Skywalker', 'email': 'luke@rebels.org'
}) # => True
rule.matches({
   'first_name': 'Darth', 'last_name': 'Vader', 'email': 'dvader@empire.net'
}) # => False

Credits

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

rule-engine-2.2.0.tar.gz (26.6 kB view details)

Uploaded Source

File details

Details for the file rule-engine-2.2.0.tar.gz.

File metadata

  • Download URL: rule-engine-2.2.0.tar.gz
  • Upload date:
  • Size: 26.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.5

File hashes

Hashes for rule-engine-2.2.0.tar.gz
Algorithm Hash digest
SHA256 17e1b031b88ea0303a6dfd64f8664cfa846832cd5d39a75b3b2cd3634fec5613
MD5 be4ebd8896e966d43753788865394096
BLAKE2b-256 d6bfbb205e68b8369ed9a2990d4bb533d21dc4713c94036bdad508cb2e05ac65

See more details on using hashes here.

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