A lightweight DSL for business rules with dependency analysis
Project description
rulang (Python)
Python implementation of the Rulang business-rules DSL. Semantic parity with the TypeScript runtime is enforced by a shared spec suite.
Install
uv add rulang
Quick start
from rulang import RuleEngine
engine = RuleEngine(mode="all_match")
engine.add_rules([
"entity.age >= 18 => entity.is_adult = true",
"entity.is_adult == true => entity.discount += 0.1",
])
entity = {"age": 25, "is_adult": False, "discount": 0.0}
engine.evaluate(entity)
# entity is now {'age': 25, 'is_adult': True, 'discount': 0.1}
The full DSL (operators, paths, built-in functions, null-safe access) is documented in the top-level README and in the runtime-shipped reference (rulang.grammar_reference()).
Tooling API at a glance
rulang.parse(text)— returns a public AST with source spans on every node.rulang.walk(node, visitor)— pre-order AST traversal.rulang.format(rule)— canonical string form. Idempotent; round-trips throughparse. Companion helpers:format_condition,format_action,format_path,format_expr.rulang.detect_conflicts(rules, mode=…)— duplicate/contradiction/shadowing findings across a rule set.engine.dry_run(entity)— structured trace with per-action before/after, aggregated diff, final entity, and return value.rulang.validate(rule, resolver, severity_overrides=…)— list ofDiagnostic. Schema-agnostic; consumers subclassBaseResolverand override hooks. Parse errors are returned as diagnostics —validatenever raises.rulang.builders— ergonomic AST constructors:rule, comparisons (eq,neq,lt,gt,lte,gte,in_,not_in,contains,startswith,endswith,matches,contains_any,contains_all), logical (and_,or_,not_), existence (exists,is_empty), actions (set_,compound,workflow_call,ret), andpathref/lit/float_lit/int_lit/fn/binary/unary/null_coalesce/workflow_expr.rulang.grammar_reference()— canonical LLM-ready grammar cheatsheet (markdown), versioned with the package.
For worked examples of each feature, see the top-level README's "Tooling API" section.
Diagnostic codes
rulang.validation.DIAGNOSTIC_CODES lists every rulang-owned code. Consumer diagnostics should use their own namespace (e.g. myapp.*). Defaults and overrides are documented in the root README.
Repository layout
src/rulang/— sourcetests/— Python-specific teststests/spec/— cross-runtime spec runners; fixtures live in../spec/cases/and../spec/feature-cases/../grammar/BusinessRules.g4— shared ANTLR grammar (source of truth)../docs/proposals/— design proposals for each capability
Development
# Dev install
uv sync --all-extras
# Run tests with coverage
uv run pytest tests/
# Regenerate parsers after grammar edits (run from repo root)
cd .. && npm run generate:parsers
License
MIT
Project details
Release history Release notifications | RSS feed
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 rulang-1.1.1.tar.gz.
File metadata
- Download URL: rulang-1.1.1.tar.gz
- Upload date:
- Size: 171.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6d0bb3b679ded38727e84ca62349fac1b83c0dc9fa87f33f1bb30d8af3255a38
|
|
| MD5 |
2dd22fe3d75ab60849b4ab7124c2e2e3
|
|
| BLAKE2b-256 |
0d747468153d857e3fb8ae77dd02a2dd6de39b7c9b56be229a5c23de3e191347
|
File details
Details for the file rulang-1.1.1-py3-none-any.whl.
File metadata
- Download URL: rulang-1.1.1-py3-none-any.whl
- Upload date:
- Size: 83.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.11.7 {"installer":{"name":"uv","version":"0.11.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
223d9cf2ee478396f2b5e2b387b57611e32ed92f072959eaf501e69d367262b6
|
|
| MD5 |
a98f469880de0d6112849aa459542bf8
|
|
| BLAKE2b-256 |
566dc6078adebf83ef117e85f55e1d92baaf4564d04b8aa60c073a9442719bfe
|