https://github.com/weaming/poseidon-rules
Validate complex json data against rules you defined
https://github.com/weaming/poseidon-rules
Last synced: 12 months ago
JSON representation
Validate complex json data against rules you defined
- Host: GitHub
- URL: https://github.com/weaming/poseidon-rules
- Owner: weaming
- Created: 2019-09-11T06:24:22.000Z (almost 7 years ago)
- Default Branch: master
- Last Pushed: 2019-12-20T09:29:24.000Z (over 6 years ago)
- Last Synced: 2025-06-09T03:44:18.004Z (about 1 year ago)
- Language: Python
- Size: 6.84 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Poseidon Rules
Validate complex json data against rules you defined.
## Philosophy of this library
Business code has complex logic, and they can be wrapped deeply, so we need a DSL to define these rules in one place.
Every logic can have two basci relation, `and` or `or`, but the `not` logic is left to the rule evaluation written by developer.
Once one rule is not satisfied, the whole logic rule will be falsy, call the help function `get_reason_stack` will find the deepest name of rule, aka the exception message wrapped in the `RuleFail`.
Rules is defined in dict format, which is bad compared to the Haskell lazy evaluation. So you can pass a closure function to the "must" or "else_must", which will be called when "if" is evaluated to true ("must") or false ("else_must") at runtime, instead of define-time. This feature make you free from caring about the exception in some situations.
## Usage
See [test](poseidon_rules/test_statement.py)