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.2.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.2-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: rulea-1.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 c008ceb8ca870879691cfafd84adb4f6ad6d57b355692f7ea851b76eb446202c
MD5 ad1d7e73cc2c52def3bdaa8f56faa400
BLAKE2b-256 d64d9082ab1dc173c600f28ed85422fe6a7ea69df71dd40b3dfcde1de043bbab

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rulea-1.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a6cf64c607a2184f29b077c908f7be5f864f403dad30eff5aae4fb3669e3faad
MD5 1a714d5e6e6a8e017cbf6987fba4a280
BLAKE2b-256 413c935922211fb979b977ce308a074b82c7cdf3506d7db950fc5798a8efb008

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