Rule engine with composable condition evaluator and pluggable action handlers.
Project description
bloque-automation
Rule engine with composable condition evaluator and pluggable action handlers.
Features
- Condition tree: AND/OR/NOT logic + comparison operators (eq, gt, in, regex, etc.)
- Sync evaluator: Pure function, no I/O, fully testable
- Pluggable handlers: ActionHandler protocol - bring your own action implementations
- Tenant-aware: Optional multitenant isolation via ulfblk-multitenant context
- Error-resilient: Missing fields return False, failed actions don't crash the engine
Install
uv add bloque-automation
Quick Start
from bloque_automation import (
Action, ActionType, Condition, LogActionHandler,
Operator, Rule, RuleEngine,
)
# Define a condition: user.age >= 18
condition = Condition(operator=Operator.GTE, field="user.age", value=18)
# Define a rule with a log action
rule = Rule(
rule_id="adult-check",
name="Adult User Check",
conditions=condition,
actions=[Action(action_type=ActionType.LOG, name="log-adult")],
)
# Create engine and register handler
engine = RuleEngine()
engine.register_handler(ActionType.LOG, LogActionHandler())
engine.add_rule(rule)
# Evaluate an event
async with engine:
results = await engine.evaluate({"user": {"age": 25}})
assert results[0].matched is True
Condition Operators
Comparison
| Operator | Description |
|---|---|
eq |
Equal |
neq |
Not equal |
gt |
Greater than |
gte |
Greater than or equal |
lt |
Less than |
lte |
Less than or equal |
in |
Value in list |
not_in |
Value not in list |
contains |
String contains |
starts_with |
String starts with |
ends_with |
String ends with |
regex |
Regex match |
Logical
| Operator | Description |
|---|---|
and |
All children must match |
or |
Any child must match |
not |
Invert single child |
Nested Fields
Use dot-path notation to access nested dict keys:
condition = Condition(operator=Operator.EQ, field="user.plan.tier", value="premium")
event = {"user": {"plan": {"tier": "premium"}}}
# evaluates to True
Custom Action Handler
Implement the ActionHandler protocol:
class NotificationActionHandler:
def __init__(self, notification_service):
self.service = notification_service
async def execute(self, action, context):
await self.service.notify_simple(
action.config["recipient"],
action.config["subject"],
str(context),
)
return {"status": "sent"}
async def health_check(self):
return True
engine.register_handler(ActionType.NOTIFY, NotificationActionHandler(svc))
Dependencies
Only ulfblk-core. Handlers that need HTTP, notifications, etc. bring their own deps.
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 ulfblk_automation-0.1.0.tar.gz.
File metadata
- Download URL: ulfblk_automation-0.1.0.tar.gz
- Upload date:
- Size: 11.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","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":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3355dcd298eb3bbd88ea88826751b31be1189c33f809f922d5f41acda6f03d28
|
|
| MD5 |
897b96c6546746cc6e8fb53f3eae08d6
|
|
| BLAKE2b-256 |
fee7939e6207345b915cc6aa356c1cd46d48c692b0d9366e71471fbb3ae04429
|
File details
Details for the file ulfblk_automation-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ulfblk_automation-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.11 {"installer":{"name":"uv","version":"0.10.11","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":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b08fb976dd55ebf7aa0d894350e768828626776e415b2351360dd9aae11499f
|
|
| MD5 |
11e87ead0ac3cb7ddb27f2c61cdb4257
|
|
| BLAKE2b-256 |
dffb08a250583f7e3b2a1d23250823ae54462a3111690d845e2d08fbde77aa2d
|