skillfed

rule-engine

A lightweight, optionally typed expression language with a custom grammar for matching arbitrary Python objects.

rule-engine v5.0.2 448.3K downloads/30d#6,604 on PyPI593
Permissive license BSD-3-Clause Active released

What it is and what it does

Rule Engine is a domain-specific language (DSL) for writing matching rules as strings in Python code. You define rules using a custom grammar similar to Python syntax, then apply them to dictionaries or objects to test whether they match. The language supports optional type annotations to catch errors early, regular expression matching on strings, datetime values, and compound types like lists, dicts, and sets.

Typical usage involves creating a Rule object with an expression string, optionally providing a typed Context to validate symbol names and operations, then calling the rule's matching method on data objects. It's designed for scenarios where you need to express filtering or matching logic in a declarative, user-friendly way rather than writing Python conditionals directly. The package includes a debug REPL for experimentation.

Use it for:

  • Filter records in a database or API response based on user-defined rule expressions without writing custom Python code
  • Implement a rules engine for workflow automation where business logic is expressed as strings and evaluated at runtime
  • Validate incoming data against typed rule sets to ensure only objects matching specific criteria proceed
  • Build a query language for applications where end users need to define matching criteria without Python knowledge
  • Match log entries or events against rule expressions for alerting or log aggregation systems

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Rule Engine provides a lightweight, custom expression language for evaluating rules against Python objects, with optional type hinting and support for regex matching, datetime handling, and compound data types.

Yes. Rule Engine is actively maintained, has no known vulnerabilities, low install friction, and solves a clear problem: declarative rule evaluation without writing Python code. The permissive BSD-3-Clause license poses no restrictions. Install if you need to evaluate user-defined or data-driven matching logic; skip if you're writing simple hardcoded conditionals.

Install

rule-engine on PyPI

pip

pip install rule-engine

uv

uv add rule-engine

poetry

poetry add rule-engine

Installing rule-engine

Before you install

Low install friction with a single runtime dependency (python-dateutil). Active maintenance with a recent release 37 days ago and ongoing repository activity.

License in practice

BSD-3-Clause permissive license allows commercial and private use without restriction.

Quickstart

pip install rule-engine

import rule_engine
rule = rule_engine.Rule('first_name == "Luke" and email =~ ".*@rebels.org$"')
rule.matches({'first_name': 'Luke', 'email': 'luke@rebels.org'})

Requires Python 3.10 or later; Version 6.0 will drop Python 3.10 support.

Verify before relying

  • Performance characteristics when evaluating large rule sets or complex expressions against many objects
  • Thread-safety guarantees beyond the documented claim in the description excerpt

Package facts

License BSD-3-Clause (permissive)
Python support supports the current Python release (>=3.10)
Install friction low — pure-Python wheel
Runtime dependencies 1 — python-dateutil
Maintenance actively maintained — 37 days since the last release
Last repo commit
First released
Downloads 448,253/month — #6,604 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: rule_engine-5.0.2-py3-none-any.whl

Development Status :: 5 - Production/StableEnvironment :: ConsoleIntended Audience :: DevelopersOperating System :: OS IndependentProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Topic :: Software Development :: Libraries :: Python Modules

Tags

rule evaluation engineexpression language matchingpattern matching rulestyped rule expressionsregex rule matchingconditional rule enginedata filtering rules
dslrule-matchingexpression-evaluation

More Python Modules packages