No project description provided
Project description
adjudicator
Adjudicator (nount): An adjudicator is a person or body that makes formal judgments on a disputed matter. They are the ones who settle disputes or decide who is right in a disagreement. This could be a judge in a courtroom, an arbitrator in a negotiation, or any person or system given the power to make decisions of this type.
Adjudicator is a framework for type-based rules engines largely inspired by the Pants build system. The rule graph consists of nodes which are concrete Python types and edges which are functions that take a set of input types and produce an output type.
Rules are matched on a set of facts, which populate the possible input types of a rule. Deriving a type may require chained execution of rules, which is supported. Global facts may be used to populate a potential input type for all rule executions.
In a way, Adjudicator can also be called a dependency injection engine.
graph LR
String --> Rule1 --> Integer
String --> Rule2 --> Integer
IntegerBase --> Rule2
In the above example, an Integer
can be derived by providing a String
as a fact and Rule1
will be executed, or
by also providing an IntegerBase
and Rule2
will be executed.
Installation
Adjudicator is available on PyPI. You need at least Python 3.10.
pip install python-adjudicator
Example code
Check out the examples/codegen/ directory for a simple example of a rules engine that generates Terraform code based on a set of Kubernetes-like resources. This example combines the resource management API with the rules engine API.
graph LR
AwsAccount["Resource[AwsAccount]"] --> AwsAccountCreation
AwsAccount["Resource[AwsAccount]"] --> AwsProviderInitialization
TerraformWorkspace["Resource[TerraformWorspace]"] --> TerraformWorkspaceCreation
The advantage of using a rules engine here is that it avoids executing the same rule again if it was already executed with the same inputs. It also makes it easier to increase the system's complexity by adding more rules without also significantly increasing the complexity of the code.
Future extensions
- Currently the rule graph stores rules as connections between types and rules on edges. A more efficient representation would be the one illustrated above, where types are connected to rules which are connected to types.
- The ability to mark facts as required to be consumed. If such a fact is not consumed during the execution of a request, an error will be raised.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for python_adjudicator-0.2.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77b56cb5144d6139e11131ec3e0eb736b0c2f54fab9da0204e1a478fd36bd8f1 |
|
MD5 | 9814ed8ad6a41dd6bdfe458c010b52b3 |
|
BLAKE2b-256 | e61085c34a7d082a680b83683089e8ccd9eba5ecfac6bec282e6a8dc5ca0c04e |