Rule-based programmable language in Python
Project description
============================== rulea - Syntax and Usage
Overview:
rulea is a rule-based language that clearly defines "who can do what." With Python-like syntax, access or operation conditions are written in external .rulea files, which can then be evaluated from within an application.
Basic Rule File Structure:
rule <rule_name>:
when: <condition_expression>
reason: ""
The when: section accepts both Python expressions and if statements.
Multi-line conditions are supported.
Examples:
rule edit:
when: user == owner and status != "locked"
reason: "Only the owner can edit unlocked items"
rule delete:
when:
if role == "admin":
True
elif user == owner:
status != "archived"
else:
False
reason: "Only admins or the owner (if not archived) can delete"
Parameters are passed in externally as a context and are evaluated as variables.
Using in Python:
from rulea import RuleEngine
engine = RuleEngine("access.rulea")
ok, reason = engine.check("edit", {
"user": "alice",
"owner": "alice",
"status": "active"
})
if ok:
print("Allowed")
else:
print("Denied:", reason)
Using in CLI:
rulea access.rulea edit \
--context '{"user": "alice", "owner": "bob", "status": "locked"}'
Exit Codes:
0 = Rule passed (allowed)
1 = Rule failed (denied)
Notes:
when: supports expressions and if statements
reason: is returned when the rule is denied
Conditions are evaluated in a safe Python environment
.rulea files must be saved in UTF-8 encoding
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file rulea-1.0.0.tar.gz.
File metadata
- Download URL: rulea-1.0.0.tar.gz
- Upload date:
- Size: 6.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0d04ba8074d8ab107a300e8fc29194e1ee912a9985fcacaf643861b2aa13786f
|
|
| MD5 |
f9386b5f47e97dde1db99ae9f4ad6deb
|
|
| BLAKE2b-256 |
2bf48c77c21093035fa7feca58c74c2f6cf4bd193b4082ebc67757db510e5675
|
Provenance
The following attestation bundles were made for rulea-1.0.0.tar.gz:
Publisher:
publish.yml on tanuki276/rulea
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rulea-1.0.0.tar.gz -
Subject digest:
0d04ba8074d8ab107a300e8fc29194e1ee912a9985fcacaf643861b2aa13786f - Sigstore transparency entry: 253356809
- Sigstore integration time:
-
Permalink:
tanuki276/rulea@e7d70f7c95b1b6f86a8dbe7f2b4643d3515f0c1e -
Branch / Tag:
refs/tags/1.0.0 - Owner: https://github.com/tanuki276
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e7d70f7c95b1b6f86a8dbe7f2b4643d3515f0c1e -
Trigger Event:
release
-
Statement type:
File details
Details for the file rulea-1.0.0-py3-none-any.whl.
File metadata
- Download URL: rulea-1.0.0-py3-none-any.whl
- Upload date:
- Size: 7.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1739123ddd42c4d33cfeebf012c40173753f0fb1ce22b56a9d07f2c62f2b79c7
|
|
| MD5 |
ad652e6b5852db281056cd3c9dde7148
|
|
| BLAKE2b-256 |
b36ecb3dd5e96ddc59492538af5ef37f24d913568805924ed7edad872cf0c92f
|
Provenance
The following attestation bundles were made for rulea-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on tanuki276/rulea
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
rulea-1.0.0-py3-none-any.whl -
Subject digest:
1739123ddd42c4d33cfeebf012c40173753f0fb1ce22b56a9d07f2c62f2b79c7 - Sigstore transparency entry: 253356811
- Sigstore integration time:
-
Permalink:
tanuki276/rulea@e7d70f7c95b1b6f86a8dbe7f2b4643d3515f0c1e -
Branch / Tag:
refs/tags/1.0.0 - Owner: https://github.com/tanuki276
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e7d70f7c95b1b6f86a8dbe7f2b4643d3515f0c1e -
Trigger Event:
release
-
Statement type: