Skip to main content

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

rulea-1.1.1.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

rulea-1.1.1-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file rulea-1.1.1.tar.gz.

File metadata

  • Download URL: rulea-1.1.1.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for rulea-1.1.1.tar.gz
Algorithm Hash digest
SHA256 d86512213ee6bf0668500182665560ed0f0a8adda54d8341d0c1b84a49d8f1b6
MD5 52a3c8ec9071b6dff16c6e214401698b
BLAKE2b-256 ce397a7c1ace81469703bd9c22c2cf97a265018fb006fa43f5ac2b54b303e520

See more details on using hashes here.

File details

Details for the file rulea-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: rulea-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for rulea-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6495cbbf9e65110e53e69f66d3faf8600ecd0d398f9d73af337cf2f94497e745
MD5 cbd1df05ad6ab39ff2fe16de8b2077c9
BLAKE2b-256 382143f97cc8fb6ac845177bd780b9492615235c00906375bf760e064680d210

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page