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.0.tar.gz (6.7 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.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

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

Hashes for rulea-1.0.0.tar.gz
Algorithm Hash digest
SHA256 0d04ba8074d8ab107a300e8fc29194e1ee912a9985fcacaf643861b2aa13786f
MD5 f9386b5f47e97dde1db99ae9f4ad6deb
BLAKE2b-256 2bf48c77c21093035fa7feca58c74c2f6cf4bd193b4082ebc67757db510e5675

See more details on using hashes here.

Provenance

The following attestation bundles were made for rulea-1.0.0.tar.gz:

Publisher: publish.yml on tanuki276/rulea

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for rulea-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1739123ddd42c4d33cfeebf012c40173753f0fb1ce22b56a9d07f2c62f2b79c7
MD5 ad652e6b5852db281056cd3c9dde7148
BLAKE2b-256 b36ecb3dd5e96ddc59492538af5ef37f24d913568805924ed7edad872cf0c92f

See more details on using hashes here.

Provenance

The following attestation bundles were made for rulea-1.0.0-py3-none-any.whl:

Publisher: publish.yml on tanuki276/rulea

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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