Name | rule-engine JSON |
Version |
4.4.0
JSON |
| download |
home_page | https://github.com/zeroSteiner/rule-engine |
Summary | A lightweight, optionally typed expression language with a custom grammar for matching arbitrary Python objects. |
upload_time | 2024-04-06 00:13:00 |
maintainer | Spencer McIntyre |
docs_url | None |
author | Spencer McIntyre |
requires_python | None |
license | BSD |
keywords |
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
Rule Engine
===========
|badge-build| |badge-pypi|
A lightweight, optionally typed expression language with a custom grammar for matching arbitrary Python objects.
Documentation is available at https://zeroSteiner.github.io/rule-engine/.
Rule Engine expressions are written in their own language, defined as strings in Python. The syntax is most similar to
Python with some inspiration from Ruby. Some features of this language includes:
- Optional type hinting
- Matching strings with regular expressions
- Datetime datatypes
- Compound datatypes (equivalents for Python dict, list and set types)
- Data attributes
- Thread safety
Example Usage
-------------
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.
.. code-block:: python
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
The next example demonstrates the optional type system. A custom context is created that defines two symbols, one string
and one float. Because symbols are defined, an exception will be raised if an unknown symbol is specified or an invalid
operation is used. See `Type Hinting`_ for more information.
.. code-block:: python
import rule_engine
# define the custom context with two symbols
context = rule_engine.Context(type_resolver=rule_engine.type_resolver_from_dict({
'first_name': rule_engine.DataType.STRING,
'age': rule_engine.DataType.FLOAT
}))
# receive an error when an unknown symbol is used
rule = rule_engine.Rule('last_name == "Vader"', context=context)
# => SymbolResolutionError: last_name
# receive an error when an invalid operation is used
rule = rule_engine.Rule('first_name + 1', context=context)
# => EvaluationError: data type mismatch
Want to give the rule expression language a try? Checkout the `Debug REPL`_ that makes experimentation easy. After
installing just run ``python -m rule_engine.debug_repl``.
Installation
------------
Install the latest release from PyPi using ``pip install rule-engine``. Releases follow `Semantic Versioning`_ to
indicate in each new version whether it fixes bugs, adds features or breaks backwards compatibility. See the
`Change Log`_ for a curated list of changes.
Credits
-------
* Spencer McIntyre - zeroSteiner |social-github|
License
-------
The Rule Engine library is released under the BSD 3-Clause license. It is able to be used for both commercial and
private purposes. For more information, see the `LICENSE`_ file.
.. |badge-build| image:: https://img.shields.io/github/actions/workflow/status/zeroSteiner/rule-engine/ci.yml?branch=master&style=flat-square
:alt: GitHub Workflow Status (branch)
:target: https://github.com/zeroSteiner/rule-engine/actions/workflows/ci.yml
.. |badge-pypi| image:: https://img.shields.io/pypi/v/rule-engine?style=flat-square
:alt: PyPI
:target: https://pypi.org/project/rule-engine/
.. |social-github| image:: https://img.shields.io/github/followers/zeroSteiner?style=social
:alt: GitHub followers
:target: https://github.com/zeroSteiner
.. |social-twitter| image:: https://img.shields.io/twitter/follow/zeroSteiner
:alt: Twitter Follow
:target: https://twitter.com/zeroSteiner
.. _Change Log: https://zerosteiner.github.io/rule-engine/change_log.html
.. _Debug REPL: https://zerosteiner.github.io/rule-engine/debug_repl.html
.. _Getting Started: https://zerosteiner.github.io/rule-engine/getting_started.html
.. _LICENSE: https://github.com/zeroSteiner/rule-engine/blob/master/LICENSE
.. _Semantic Versioning: https://semver.org/
.. _Type Hinting: https://zerosteiner.github.io/rule-engine/getting_started.html#type-hinting
Raw data
{
"_id": null,
"home_page": "https://github.com/zeroSteiner/rule-engine",
"name": "rule-engine",
"maintainer": "Spencer McIntyre",
"docs_url": null,
"requires_python": null,
"maintainer_email": "zeroSteiner@gmail.com",
"keywords": null,
"author": "Spencer McIntyre",
"author_email": "zeroSteiner@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/c4/49/b1bb10196e12045dedee0ae68e1b8b5fe68fa81edd5c3a55364effc71f6c/rule-engine-4.4.0.tar.gz",
"platform": null,
"description": "Rule Engine\n===========\n|badge-build| |badge-pypi|\n\nA lightweight, optionally typed expression language with a custom grammar for matching arbitrary Python objects.\n\nDocumentation is available at https://zeroSteiner.github.io/rule-engine/.\n\nRule Engine expressions are written in their own language, defined as strings in Python. The syntax is most similar to\nPython with some inspiration from Ruby. Some features of this language includes:\n\n- Optional type hinting\n- Matching strings with regular expressions\n- Datetime datatypes\n- Compound datatypes (equivalents for Python dict, list and set types)\n- Data attributes\n- Thread safety\n\nExample Usage\n-------------\nThe following example demonstrates the basic usage of defining a rule object and applying it to two dictionaries,\nshowing that one matches while the other does not. See `Getting Started`_ for more information.\n\n.. code-block:: python\n\n import rule_engine\n # match a literal first name and applying a regex to the email\n rule = rule_engine.Rule(\n 'first_name == \"Luke\" and email =~ \".*@rebels.org$\"'\n ) # => <Rule text='first_name == \"Luke\" and email =~ \".*@rebels.org$\"' >\n rule.matches({\n 'first_name': 'Luke', 'last_name': 'Skywalker', 'email': 'luke@rebels.org'\n }) # => True\n rule.matches({\n 'first_name': 'Darth', 'last_name': 'Vader', 'email': 'dvader@empire.net'\n }) # => False\n\nThe next example demonstrates the optional type system. A custom context is created that defines two symbols, one string\nand one float. Because symbols are defined, an exception will be raised if an unknown symbol is specified or an invalid\noperation is used. See `Type Hinting`_ for more information.\n\n.. code-block:: python\n\n import rule_engine\n # define the custom context with two symbols\n context = rule_engine.Context(type_resolver=rule_engine.type_resolver_from_dict({\n 'first_name': rule_engine.DataType.STRING,\n 'age': rule_engine.DataType.FLOAT\n }))\n\n # receive an error when an unknown symbol is used\n rule = rule_engine.Rule('last_name == \"Vader\"', context=context)\n # => SymbolResolutionError: last_name\n\n # receive an error when an invalid operation is used\n rule = rule_engine.Rule('first_name + 1', context=context)\n # => EvaluationError: data type mismatch\n\nWant to give the rule expression language a try? Checkout the `Debug REPL`_ that makes experimentation easy. After\ninstalling just run ``python -m rule_engine.debug_repl``.\n\nInstallation\n------------\nInstall the latest release from PyPi using ``pip install rule-engine``. Releases follow `Semantic Versioning`_ to\nindicate in each new version whether it fixes bugs, adds features or breaks backwards compatibility. See the\n`Change Log`_ for a curated list of changes.\n\nCredits\n-------\n* Spencer McIntyre - zeroSteiner |social-github|\n\nLicense\n-------\nThe Rule Engine library is released under the BSD 3-Clause license. It is able to be used for both commercial and\nprivate purposes. For more information, see the `LICENSE`_ file.\n\n.. |badge-build| image:: https://img.shields.io/github/actions/workflow/status/zeroSteiner/rule-engine/ci.yml?branch=master&style=flat-square\n :alt: GitHub Workflow Status (branch)\n :target: https://github.com/zeroSteiner/rule-engine/actions/workflows/ci.yml\n\n.. |badge-pypi| image:: https://img.shields.io/pypi/v/rule-engine?style=flat-square\n :alt: PyPI\n :target: https://pypi.org/project/rule-engine/\n\n.. |social-github| image:: https://img.shields.io/github/followers/zeroSteiner?style=social\n :alt: GitHub followers\n :target: https://github.com/zeroSteiner\n\n.. |social-twitter| image:: https://img.shields.io/twitter/follow/zeroSteiner\n :alt: Twitter Follow\n :target: https://twitter.com/zeroSteiner\n\n.. _Change Log: https://zerosteiner.github.io/rule-engine/change_log.html\n.. _Debug REPL: https://zerosteiner.github.io/rule-engine/debug_repl.html\n.. _Getting Started: https://zerosteiner.github.io/rule-engine/getting_started.html\n.. _LICENSE: https://github.com/zeroSteiner/rule-engine/blob/master/LICENSE\n.. _Semantic Versioning: https://semver.org/\n.. _Type Hinting: https://zerosteiner.github.io/rule-engine/getting_started.html#type-hinting\n",
"bugtrack_url": null,
"license": "BSD",
"summary": "A lightweight, optionally typed expression language with a custom grammar for matching arbitrary Python objects.",
"version": "4.4.0",
"project_urls": {
"Homepage": "https://github.com/zeroSteiner/rule-engine"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c449b1bb10196e12045dedee0ae68e1b8b5fe68fa81edd5c3a55364effc71f6c",
"md5": "0cb0c026c90b0942a517fc342f33b02e",
"sha256": "a358592b95316969a1e3c66fb0fdd457a2189f31891a6c1425d0308c1d6b19bc"
},
"downloads": -1,
"filename": "rule-engine-4.4.0.tar.gz",
"has_sig": false,
"md5_digest": "0cb0c026c90b0942a517fc342f33b02e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 44717,
"upload_time": "2024-04-06T00:13:00",
"upload_time_iso_8601": "2024-04-06T00:13:00.580041Z",
"url": "https://files.pythonhosted.org/packages/c4/49/b1bb10196e12045dedee0ae68e1b8b5fe68fa81edd5c3a55364effc71f6c/rule-engine-4.4.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-04-06 00:13:00",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "zeroSteiner",
"github_project": "rule-engine",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "rule-engine"
}