async-rule-engine 4.6.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- async_rule_engine-4.6.0/LICENSE +28 -0
- async_rule_engine-4.6.0/PKG-INFO +142 -0
- async_rule_engine-4.6.0/README.rst +102 -0
- async_rule_engine-4.6.0/lib/async_rule_engine.egg-info/PKG-INFO +142 -0
- async_rule_engine-4.6.0/lib/async_rule_engine.egg-info/SOURCES.txt +21 -0
- async_rule_engine-4.6.0/lib/async_rule_engine.egg-info/dependency_links.txt +1 -0
- async_rule_engine-4.6.0/lib/async_rule_engine.egg-info/requires.txt +2 -0
- async_rule_engine-4.6.0/lib/async_rule_engine.egg-info/top_level.txt +1 -0
- async_rule_engine-4.6.0/lib/rule_engine/__init__.py +47 -0
- async_rule_engine-4.6.0/lib/rule_engine/ast.py +1614 -0
- async_rule_engine-4.6.0/lib/rule_engine/builtins.py +214 -0
- async_rule_engine-4.6.0/lib/rule_engine/debug_ast.py +65 -0
- async_rule_engine-4.6.0/lib/rule_engine/debug_repl.py +144 -0
- async_rule_engine-4.6.0/lib/rule_engine/engine.py +731 -0
- async_rule_engine-4.6.0/lib/rule_engine/errors.py +311 -0
- async_rule_engine-4.6.0/lib/rule_engine/parser/__init__.py +564 -0
- async_rule_engine-4.6.0/lib/rule_engine/parser/base.py +82 -0
- async_rule_engine-4.6.0/lib/rule_engine/parser/parsetab.py +98 -0
- async_rule_engine-4.6.0/lib/rule_engine/parser/utilities.py +115 -0
- async_rule_engine-4.6.0/lib/rule_engine/suggestions.py +102 -0
- async_rule_engine-4.6.0/lib/rule_engine/types.py +618 -0
- async_rule_engine-4.6.0/setup.cfg +4 -0
- async_rule_engine-4.6.0/setup.py +99 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
Copyright (c) 2020, Spencer McIntyre
|
|
2
|
+
All rights reserved.
|
|
3
|
+
|
|
4
|
+
Redistribution and use in source and binary forms, with or without
|
|
5
|
+
modification, are permitted provided that the following conditions are
|
|
6
|
+
met:
|
|
7
|
+
|
|
8
|
+
* Redistributions of source code must retain the above copyright
|
|
9
|
+
notice, this list of conditions and the following disclaimer.
|
|
10
|
+
* Redistributions in binary form must reproduce the above
|
|
11
|
+
copyright notice, this list of conditions and the following disclaimer
|
|
12
|
+
in the documentation and/or other materials provided with the
|
|
13
|
+
distribution.
|
|
14
|
+
* Neither the name of the project nor the names of its
|
|
15
|
+
contributors may be used to endorse or promote products derived from
|
|
16
|
+
this software without specific prior written permission.
|
|
17
|
+
|
|
18
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
19
|
+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
20
|
+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
21
|
+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
22
|
+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
23
|
+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
24
|
+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
25
|
+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
26
|
+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
27
|
+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: async-rule-engine
|
|
3
|
+
Version: 4.6.0
|
|
4
|
+
Summary: A lightweight, optionally typed expression language with a custom grammar for matching arbitrary Python objects.
|
|
5
|
+
Home-page: https://github.com/ali-kazmi85/rule-engine
|
|
6
|
+
Author: Ali Kazmi
|
|
7
|
+
Author-email: ali.kazmi@10pearls.com
|
|
8
|
+
Maintainer: Ali Kazmi
|
|
9
|
+
Maintainer-email: ali.kazmi@10pearls.com
|
|
10
|
+
License: BSD
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: BSD License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.6
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
|
+
Description-Content-Type: text/x-rst
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: ply>=3.9
|
|
27
|
+
Requires-Dist: python-dateutil~=2.7
|
|
28
|
+
Dynamic: author
|
|
29
|
+
Dynamic: author-email
|
|
30
|
+
Dynamic: classifier
|
|
31
|
+
Dynamic: description
|
|
32
|
+
Dynamic: description-content-type
|
|
33
|
+
Dynamic: home-page
|
|
34
|
+
Dynamic: license
|
|
35
|
+
Dynamic: license-file
|
|
36
|
+
Dynamic: maintainer
|
|
37
|
+
Dynamic: maintainer-email
|
|
38
|
+
Dynamic: requires-dist
|
|
39
|
+
Dynamic: summary
|
|
40
|
+
|
|
41
|
+
Rule Engine
|
|
42
|
+
===========
|
|
43
|
+
|badge-build| |badge-pypi|
|
|
44
|
+
|
|
45
|
+
A lightweight, optionally typed expression language with a custom grammar for matching arbitrary Python objects.
|
|
46
|
+
|
|
47
|
+
Documentation is available at https://zeroSteiner.github.io/rule-engine/.
|
|
48
|
+
|
|
49
|
+
:Warning:
|
|
50
|
+
The next major version (5.0) will remove support Python versions 3.6, 3.7 and 3.8. There is currently no timeline for
|
|
51
|
+
its release.
|
|
52
|
+
|
|
53
|
+
Rule Engine expressions are written in their own language, defined as strings in Python. The syntax is most similar to
|
|
54
|
+
Python with some inspiration from Ruby. Some features of this language includes:
|
|
55
|
+
|
|
56
|
+
- Optional type hinting
|
|
57
|
+
- Matching strings with regular expressions
|
|
58
|
+
- Datetime datatypes
|
|
59
|
+
- Compound datatypes (equivalents for Python dict, list and set types)
|
|
60
|
+
- Data attributes
|
|
61
|
+
- Thread safety
|
|
62
|
+
|
|
63
|
+
Example Usage
|
|
64
|
+
-------------
|
|
65
|
+
The following example demonstrates the basic usage of defining a rule object and applying it to two dictionaries,
|
|
66
|
+
showing that one matches while the other does not. See `Getting Started`_ for more information.
|
|
67
|
+
|
|
68
|
+
.. code-block:: python
|
|
69
|
+
|
|
70
|
+
import rule_engine
|
|
71
|
+
# match a literal first name and applying a regex to the email
|
|
72
|
+
rule = rule_engine.Rule(
|
|
73
|
+
'first_name == "Luke" and email =~ ".*@rebels.org$"'
|
|
74
|
+
) # => <Rule text='first_name == "Luke" and email =~ ".*@rebels.org$"' >
|
|
75
|
+
rule.matches({
|
|
76
|
+
'first_name': 'Luke', 'last_name': 'Skywalker', 'email': 'luke@rebels.org'
|
|
77
|
+
}) # => True
|
|
78
|
+
rule.matches({
|
|
79
|
+
'first_name': 'Darth', 'last_name': 'Vader', 'email': 'dvader@empire.net'
|
|
80
|
+
}) # => False
|
|
81
|
+
|
|
82
|
+
The next example demonstrates the optional type system. A custom context is created that defines two symbols, one string
|
|
83
|
+
and one float. Because symbols are defined, an exception will be raised if an unknown symbol is specified or an invalid
|
|
84
|
+
operation is used. See `Type Hinting`_ for more information.
|
|
85
|
+
|
|
86
|
+
.. code-block:: python
|
|
87
|
+
|
|
88
|
+
import rule_engine
|
|
89
|
+
# define the custom context with two symbols
|
|
90
|
+
context = rule_engine.Context(type_resolver=rule_engine.type_resolver_from_dict({
|
|
91
|
+
'first_name': rule_engine.DataType.STRING,
|
|
92
|
+
'age': rule_engine.DataType.FLOAT
|
|
93
|
+
}))
|
|
94
|
+
|
|
95
|
+
# receive an error when an unknown symbol is used
|
|
96
|
+
rule = rule_engine.Rule('last_name == "Vader"', context=context)
|
|
97
|
+
# => SymbolResolutionError: last_name
|
|
98
|
+
|
|
99
|
+
# receive an error when an invalid operation is used
|
|
100
|
+
rule = rule_engine.Rule('first_name + 1', context=context)
|
|
101
|
+
# => EvaluationError: data type mismatch
|
|
102
|
+
|
|
103
|
+
Want to give the rule expression language a try? Checkout the `Debug REPL`_ that makes experimentation easy. After
|
|
104
|
+
installing just run ``python -m rule_engine.debug_repl``.
|
|
105
|
+
|
|
106
|
+
Installation
|
|
107
|
+
------------
|
|
108
|
+
Install the latest release from PyPi using ``pip install rule-engine``. Releases follow `Semantic Versioning`_ to
|
|
109
|
+
indicate in each new version whether it fixes bugs, adds features or breaks backwards compatibility. See the
|
|
110
|
+
`Change Log`_ for a curated list of changes.
|
|
111
|
+
|
|
112
|
+
Credits
|
|
113
|
+
-------
|
|
114
|
+
* Spencer McIntyre - zeroSteiner |social-github|
|
|
115
|
+
|
|
116
|
+
License
|
|
117
|
+
-------
|
|
118
|
+
The Rule Engine library is released under the BSD 3-Clause license. It is able to be used for both commercial and
|
|
119
|
+
private purposes. For more information, see the `LICENSE`_ file.
|
|
120
|
+
|
|
121
|
+
.. |badge-build| image:: https://img.shields.io/github/actions/workflow/status/zeroSteiner/rule-engine/ci.yml?branch=master&style=flat-square
|
|
122
|
+
:alt: GitHub Workflow Status (branch)
|
|
123
|
+
:target: https://github.com/zeroSteiner/rule-engine/actions/workflows/ci.yml
|
|
124
|
+
|
|
125
|
+
.. |badge-pypi| image:: https://img.shields.io/pypi/v/rule-engine?style=flat-square
|
|
126
|
+
:alt: PyPI
|
|
127
|
+
:target: https://pypi.org/project/rule-engine/
|
|
128
|
+
|
|
129
|
+
.. |social-github| image:: https://img.shields.io/github/followers/zeroSteiner?style=social
|
|
130
|
+
:alt: GitHub followers
|
|
131
|
+
:target: https://github.com/zeroSteiner
|
|
132
|
+
|
|
133
|
+
.. |social-twitter| image:: https://img.shields.io/twitter/follow/zeroSteiner
|
|
134
|
+
:alt: Twitter Follow
|
|
135
|
+
:target: https://twitter.com/zeroSteiner
|
|
136
|
+
|
|
137
|
+
.. _Change Log: https://zerosteiner.github.io/rule-engine/change_log.html
|
|
138
|
+
.. _Debug REPL: https://zerosteiner.github.io/rule-engine/debug_repl.html
|
|
139
|
+
.. _Getting Started: https://zerosteiner.github.io/rule-engine/getting_started.html
|
|
140
|
+
.. _LICENSE: https://github.com/zeroSteiner/rule-engine/blob/master/LICENSE
|
|
141
|
+
.. _Semantic Versioning: https://semver.org/
|
|
142
|
+
.. _Type Hinting: https://zerosteiner.github.io/rule-engine/getting_started.html#type-hinting
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
Rule Engine
|
|
2
|
+
===========
|
|
3
|
+
|badge-build| |badge-pypi|
|
|
4
|
+
|
|
5
|
+
A lightweight, optionally typed expression language with a custom grammar for matching arbitrary Python objects.
|
|
6
|
+
|
|
7
|
+
Documentation is available at https://zeroSteiner.github.io/rule-engine/.
|
|
8
|
+
|
|
9
|
+
:Warning:
|
|
10
|
+
The next major version (5.0) will remove support Python versions 3.6, 3.7 and 3.8. There is currently no timeline for
|
|
11
|
+
its release.
|
|
12
|
+
|
|
13
|
+
Rule Engine expressions are written in their own language, defined as strings in Python. The syntax is most similar to
|
|
14
|
+
Python with some inspiration from Ruby. Some features of this language includes:
|
|
15
|
+
|
|
16
|
+
- Optional type hinting
|
|
17
|
+
- Matching strings with regular expressions
|
|
18
|
+
- Datetime datatypes
|
|
19
|
+
- Compound datatypes (equivalents for Python dict, list and set types)
|
|
20
|
+
- Data attributes
|
|
21
|
+
- Thread safety
|
|
22
|
+
|
|
23
|
+
Example Usage
|
|
24
|
+
-------------
|
|
25
|
+
The following example demonstrates the basic usage of defining a rule object and applying it to two dictionaries,
|
|
26
|
+
showing that one matches while the other does not. See `Getting Started`_ for more information.
|
|
27
|
+
|
|
28
|
+
.. code-block:: python
|
|
29
|
+
|
|
30
|
+
import rule_engine
|
|
31
|
+
# match a literal first name and applying a regex to the email
|
|
32
|
+
rule = rule_engine.Rule(
|
|
33
|
+
'first_name == "Luke" and email =~ ".*@rebels.org$"'
|
|
34
|
+
) # => <Rule text='first_name == "Luke" and email =~ ".*@rebels.org$"' >
|
|
35
|
+
rule.matches({
|
|
36
|
+
'first_name': 'Luke', 'last_name': 'Skywalker', 'email': 'luke@rebels.org'
|
|
37
|
+
}) # => True
|
|
38
|
+
rule.matches({
|
|
39
|
+
'first_name': 'Darth', 'last_name': 'Vader', 'email': 'dvader@empire.net'
|
|
40
|
+
}) # => False
|
|
41
|
+
|
|
42
|
+
The next example demonstrates the optional type system. A custom context is created that defines two symbols, one string
|
|
43
|
+
and one float. Because symbols are defined, an exception will be raised if an unknown symbol is specified or an invalid
|
|
44
|
+
operation is used. See `Type Hinting`_ for more information.
|
|
45
|
+
|
|
46
|
+
.. code-block:: python
|
|
47
|
+
|
|
48
|
+
import rule_engine
|
|
49
|
+
# define the custom context with two symbols
|
|
50
|
+
context = rule_engine.Context(type_resolver=rule_engine.type_resolver_from_dict({
|
|
51
|
+
'first_name': rule_engine.DataType.STRING,
|
|
52
|
+
'age': rule_engine.DataType.FLOAT
|
|
53
|
+
}))
|
|
54
|
+
|
|
55
|
+
# receive an error when an unknown symbol is used
|
|
56
|
+
rule = rule_engine.Rule('last_name == "Vader"', context=context)
|
|
57
|
+
# => SymbolResolutionError: last_name
|
|
58
|
+
|
|
59
|
+
# receive an error when an invalid operation is used
|
|
60
|
+
rule = rule_engine.Rule('first_name + 1', context=context)
|
|
61
|
+
# => EvaluationError: data type mismatch
|
|
62
|
+
|
|
63
|
+
Want to give the rule expression language a try? Checkout the `Debug REPL`_ that makes experimentation easy. After
|
|
64
|
+
installing just run ``python -m rule_engine.debug_repl``.
|
|
65
|
+
|
|
66
|
+
Installation
|
|
67
|
+
------------
|
|
68
|
+
Install the latest release from PyPi using ``pip install rule-engine``. Releases follow `Semantic Versioning`_ to
|
|
69
|
+
indicate in each new version whether it fixes bugs, adds features or breaks backwards compatibility. See the
|
|
70
|
+
`Change Log`_ for a curated list of changes.
|
|
71
|
+
|
|
72
|
+
Credits
|
|
73
|
+
-------
|
|
74
|
+
* Spencer McIntyre - zeroSteiner |social-github|
|
|
75
|
+
|
|
76
|
+
License
|
|
77
|
+
-------
|
|
78
|
+
The Rule Engine library is released under the BSD 3-Clause license. It is able to be used for both commercial and
|
|
79
|
+
private purposes. For more information, see the `LICENSE`_ file.
|
|
80
|
+
|
|
81
|
+
.. |badge-build| image:: https://img.shields.io/github/actions/workflow/status/zeroSteiner/rule-engine/ci.yml?branch=master&style=flat-square
|
|
82
|
+
:alt: GitHub Workflow Status (branch)
|
|
83
|
+
:target: https://github.com/zeroSteiner/rule-engine/actions/workflows/ci.yml
|
|
84
|
+
|
|
85
|
+
.. |badge-pypi| image:: https://img.shields.io/pypi/v/rule-engine?style=flat-square
|
|
86
|
+
:alt: PyPI
|
|
87
|
+
:target: https://pypi.org/project/rule-engine/
|
|
88
|
+
|
|
89
|
+
.. |social-github| image:: https://img.shields.io/github/followers/zeroSteiner?style=social
|
|
90
|
+
:alt: GitHub followers
|
|
91
|
+
:target: https://github.com/zeroSteiner
|
|
92
|
+
|
|
93
|
+
.. |social-twitter| image:: https://img.shields.io/twitter/follow/zeroSteiner
|
|
94
|
+
:alt: Twitter Follow
|
|
95
|
+
:target: https://twitter.com/zeroSteiner
|
|
96
|
+
|
|
97
|
+
.. _Change Log: https://zerosteiner.github.io/rule-engine/change_log.html
|
|
98
|
+
.. _Debug REPL: https://zerosteiner.github.io/rule-engine/debug_repl.html
|
|
99
|
+
.. _Getting Started: https://zerosteiner.github.io/rule-engine/getting_started.html
|
|
100
|
+
.. _LICENSE: https://github.com/zeroSteiner/rule-engine/blob/master/LICENSE
|
|
101
|
+
.. _Semantic Versioning: https://semver.org/
|
|
102
|
+
.. _Type Hinting: https://zerosteiner.github.io/rule-engine/getting_started.html#type-hinting
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: async-rule-engine
|
|
3
|
+
Version: 4.6.0
|
|
4
|
+
Summary: A lightweight, optionally typed expression language with a custom grammar for matching arbitrary Python objects.
|
|
5
|
+
Home-page: https://github.com/ali-kazmi85/rule-engine
|
|
6
|
+
Author: Ali Kazmi
|
|
7
|
+
Author-email: ali.kazmi@10pearls.com
|
|
8
|
+
Maintainer: Ali Kazmi
|
|
9
|
+
Maintainer-email: ali.kazmi@10pearls.com
|
|
10
|
+
License: BSD
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
+
Classifier: Environment :: Console
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: BSD License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.6
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.7
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
23
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
24
|
+
Description-Content-Type: text/x-rst
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: ply>=3.9
|
|
27
|
+
Requires-Dist: python-dateutil~=2.7
|
|
28
|
+
Dynamic: author
|
|
29
|
+
Dynamic: author-email
|
|
30
|
+
Dynamic: classifier
|
|
31
|
+
Dynamic: description
|
|
32
|
+
Dynamic: description-content-type
|
|
33
|
+
Dynamic: home-page
|
|
34
|
+
Dynamic: license
|
|
35
|
+
Dynamic: license-file
|
|
36
|
+
Dynamic: maintainer
|
|
37
|
+
Dynamic: maintainer-email
|
|
38
|
+
Dynamic: requires-dist
|
|
39
|
+
Dynamic: summary
|
|
40
|
+
|
|
41
|
+
Rule Engine
|
|
42
|
+
===========
|
|
43
|
+
|badge-build| |badge-pypi|
|
|
44
|
+
|
|
45
|
+
A lightweight, optionally typed expression language with a custom grammar for matching arbitrary Python objects.
|
|
46
|
+
|
|
47
|
+
Documentation is available at https://zeroSteiner.github.io/rule-engine/.
|
|
48
|
+
|
|
49
|
+
:Warning:
|
|
50
|
+
The next major version (5.0) will remove support Python versions 3.6, 3.7 and 3.8. There is currently no timeline for
|
|
51
|
+
its release.
|
|
52
|
+
|
|
53
|
+
Rule Engine expressions are written in their own language, defined as strings in Python. The syntax is most similar to
|
|
54
|
+
Python with some inspiration from Ruby. Some features of this language includes:
|
|
55
|
+
|
|
56
|
+
- Optional type hinting
|
|
57
|
+
- Matching strings with regular expressions
|
|
58
|
+
- Datetime datatypes
|
|
59
|
+
- Compound datatypes (equivalents for Python dict, list and set types)
|
|
60
|
+
- Data attributes
|
|
61
|
+
- Thread safety
|
|
62
|
+
|
|
63
|
+
Example Usage
|
|
64
|
+
-------------
|
|
65
|
+
The following example demonstrates the basic usage of defining a rule object and applying it to two dictionaries,
|
|
66
|
+
showing that one matches while the other does not. See `Getting Started`_ for more information.
|
|
67
|
+
|
|
68
|
+
.. code-block:: python
|
|
69
|
+
|
|
70
|
+
import rule_engine
|
|
71
|
+
# match a literal first name and applying a regex to the email
|
|
72
|
+
rule = rule_engine.Rule(
|
|
73
|
+
'first_name == "Luke" and email =~ ".*@rebels.org$"'
|
|
74
|
+
) # => <Rule text='first_name == "Luke" and email =~ ".*@rebels.org$"' >
|
|
75
|
+
rule.matches({
|
|
76
|
+
'first_name': 'Luke', 'last_name': 'Skywalker', 'email': 'luke@rebels.org'
|
|
77
|
+
}) # => True
|
|
78
|
+
rule.matches({
|
|
79
|
+
'first_name': 'Darth', 'last_name': 'Vader', 'email': 'dvader@empire.net'
|
|
80
|
+
}) # => False
|
|
81
|
+
|
|
82
|
+
The next example demonstrates the optional type system. A custom context is created that defines two symbols, one string
|
|
83
|
+
and one float. Because symbols are defined, an exception will be raised if an unknown symbol is specified or an invalid
|
|
84
|
+
operation is used. See `Type Hinting`_ for more information.
|
|
85
|
+
|
|
86
|
+
.. code-block:: python
|
|
87
|
+
|
|
88
|
+
import rule_engine
|
|
89
|
+
# define the custom context with two symbols
|
|
90
|
+
context = rule_engine.Context(type_resolver=rule_engine.type_resolver_from_dict({
|
|
91
|
+
'first_name': rule_engine.DataType.STRING,
|
|
92
|
+
'age': rule_engine.DataType.FLOAT
|
|
93
|
+
}))
|
|
94
|
+
|
|
95
|
+
# receive an error when an unknown symbol is used
|
|
96
|
+
rule = rule_engine.Rule('last_name == "Vader"', context=context)
|
|
97
|
+
# => SymbolResolutionError: last_name
|
|
98
|
+
|
|
99
|
+
# receive an error when an invalid operation is used
|
|
100
|
+
rule = rule_engine.Rule('first_name + 1', context=context)
|
|
101
|
+
# => EvaluationError: data type mismatch
|
|
102
|
+
|
|
103
|
+
Want to give the rule expression language a try? Checkout the `Debug REPL`_ that makes experimentation easy. After
|
|
104
|
+
installing just run ``python -m rule_engine.debug_repl``.
|
|
105
|
+
|
|
106
|
+
Installation
|
|
107
|
+
------------
|
|
108
|
+
Install the latest release from PyPi using ``pip install rule-engine``. Releases follow `Semantic Versioning`_ to
|
|
109
|
+
indicate in each new version whether it fixes bugs, adds features or breaks backwards compatibility. See the
|
|
110
|
+
`Change Log`_ for a curated list of changes.
|
|
111
|
+
|
|
112
|
+
Credits
|
|
113
|
+
-------
|
|
114
|
+
* Spencer McIntyre - zeroSteiner |social-github|
|
|
115
|
+
|
|
116
|
+
License
|
|
117
|
+
-------
|
|
118
|
+
The Rule Engine library is released under the BSD 3-Clause license. It is able to be used for both commercial and
|
|
119
|
+
private purposes. For more information, see the `LICENSE`_ file.
|
|
120
|
+
|
|
121
|
+
.. |badge-build| image:: https://img.shields.io/github/actions/workflow/status/zeroSteiner/rule-engine/ci.yml?branch=master&style=flat-square
|
|
122
|
+
:alt: GitHub Workflow Status (branch)
|
|
123
|
+
:target: https://github.com/zeroSteiner/rule-engine/actions/workflows/ci.yml
|
|
124
|
+
|
|
125
|
+
.. |badge-pypi| image:: https://img.shields.io/pypi/v/rule-engine?style=flat-square
|
|
126
|
+
:alt: PyPI
|
|
127
|
+
:target: https://pypi.org/project/rule-engine/
|
|
128
|
+
|
|
129
|
+
.. |social-github| image:: https://img.shields.io/github/followers/zeroSteiner?style=social
|
|
130
|
+
:alt: GitHub followers
|
|
131
|
+
:target: https://github.com/zeroSteiner
|
|
132
|
+
|
|
133
|
+
.. |social-twitter| image:: https://img.shields.io/twitter/follow/zeroSteiner
|
|
134
|
+
:alt: Twitter Follow
|
|
135
|
+
:target: https://twitter.com/zeroSteiner
|
|
136
|
+
|
|
137
|
+
.. _Change Log: https://zerosteiner.github.io/rule-engine/change_log.html
|
|
138
|
+
.. _Debug REPL: https://zerosteiner.github.io/rule-engine/debug_repl.html
|
|
139
|
+
.. _Getting Started: https://zerosteiner.github.io/rule-engine/getting_started.html
|
|
140
|
+
.. _LICENSE: https://github.com/zeroSteiner/rule-engine/blob/master/LICENSE
|
|
141
|
+
.. _Semantic Versioning: https://semver.org/
|
|
142
|
+
.. _Type Hinting: https://zerosteiner.github.io/rule-engine/getting_started.html#type-hinting
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.rst
|
|
3
|
+
setup.py
|
|
4
|
+
lib/async_rule_engine.egg-info/PKG-INFO
|
|
5
|
+
lib/async_rule_engine.egg-info/SOURCES.txt
|
|
6
|
+
lib/async_rule_engine.egg-info/dependency_links.txt
|
|
7
|
+
lib/async_rule_engine.egg-info/requires.txt
|
|
8
|
+
lib/async_rule_engine.egg-info/top_level.txt
|
|
9
|
+
lib/rule_engine/__init__.py
|
|
10
|
+
lib/rule_engine/ast.py
|
|
11
|
+
lib/rule_engine/builtins.py
|
|
12
|
+
lib/rule_engine/debug_ast.py
|
|
13
|
+
lib/rule_engine/debug_repl.py
|
|
14
|
+
lib/rule_engine/engine.py
|
|
15
|
+
lib/rule_engine/errors.py
|
|
16
|
+
lib/rule_engine/suggestions.py
|
|
17
|
+
lib/rule_engine/types.py
|
|
18
|
+
lib/rule_engine/parser/__init__.py
|
|
19
|
+
lib/rule_engine/parser/base.py
|
|
20
|
+
lib/rule_engine/parser/parsetab.py
|
|
21
|
+
lib/rule_engine/parser/utilities.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
rule_engine
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#!/usr/bin/env python3
|
|
2
|
+
# -*- coding: utf-8 -*-
|
|
3
|
+
#
|
|
4
|
+
# rule_engine/__init__.py
|
|
5
|
+
#
|
|
6
|
+
# Redistribution and use in source and binary forms, with or without
|
|
7
|
+
# modification, are permitted provided that the following conditions are
|
|
8
|
+
# met:
|
|
9
|
+
#
|
|
10
|
+
# * Redistributions of source code must retain the above copyright
|
|
11
|
+
# notice, this list of conditions and the following disclaimer.
|
|
12
|
+
# * Redistributions in binary form must reproduce the above
|
|
13
|
+
# copyright notice, this list of conditions and the following disclaimer
|
|
14
|
+
# in the documentation and/or other materials provided with the
|
|
15
|
+
# distribution.
|
|
16
|
+
# * Neither the name of the project nor the names of its
|
|
17
|
+
# contributors may be used to endorse or promote products derived from
|
|
18
|
+
# this software without specific prior written permission.
|
|
19
|
+
#
|
|
20
|
+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
21
|
+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
22
|
+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
23
|
+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
24
|
+
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
25
|
+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
26
|
+
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
27
|
+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
28
|
+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
29
|
+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
30
|
+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
31
|
+
#
|
|
32
|
+
|
|
33
|
+
__version__ = '4.6.0'
|
|
34
|
+
|
|
35
|
+
from .engine import resolve_attribute
|
|
36
|
+
from .engine import resolve_item
|
|
37
|
+
from .engine import type_resolver_from_dict
|
|
38
|
+
from .engine import Context
|
|
39
|
+
from .engine import Rule
|
|
40
|
+
|
|
41
|
+
from .errors import AttributeResolutionError
|
|
42
|
+
from .errors import EngineError
|
|
43
|
+
from .errors import EvaluationError
|
|
44
|
+
from .errors import RuleSyntaxError
|
|
45
|
+
from .errors import SymbolResolutionError
|
|
46
|
+
|
|
47
|
+
from .types import DataType
|