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.0.1.tar.gz (7.0 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.0.1-py3-none-any.whl (7.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for rulea-1.0.1.tar.gz
Algorithm Hash digest
SHA256 90ef31fdcd1ddf6d5fac0699fb04a530cc70cc265eb760ac65ed3a04e603a639
MD5 6a066a19bb9462645d5211f35d32c5c8
BLAKE2b-256 c80b266a351ed4d1f8a79eb19cfeb0c9c48b1bba6122366c66a583bf0b690df4

See more details on using hashes here.

File details

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

File metadata

  • Download URL: rulea-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.8 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.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 aba92b16d17c67784403ac2cdcf2d39fb2a8ffe5c1ff16a18ea4f324aa3aadd9
MD5 08dbbc13fd177b3a4291083689e75f1d
BLAKE2b-256 b4fe7ccb9ca4850c9ad8ee0adab633fcc1cb5c75e91eb02603344755200d8d83

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