{"id":14899,"library":"rule-engine","title":"rule-engine Expression Language","description":"rule-engine is a lightweight, optionally typed expression language with a custom grammar for matching arbitrary Python objects. It provides a simple way to define and evaluate complex rules against data, supporting various data types and custom functions. The current stable version is 4.5.3, with frequent patch releases and a v5 alpha in active development.","status":"active","version":"4.5.3","language":"en","source_language":"en","source_url":"https://github.com/zeroSteiner/rule-engine","tags":["expression-language","rules-engine","parsing","evaluation","data-matching","dsl"],"install":[{"cmd":"pip install rule-engine","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"Rule","correct":"from rule_engine import Rule"},{"note":"Used for advanced scenarios like custom functions or type definitions.","symbol":"Context","correct":"from rule_engine import Context"},{"note":"Essential when defining custom data types or explicit type coercions.","symbol":"DataType","correct":"from rule_engine import DataType"}],"quickstart":{"code":"from rule_engine import Rule\n\n# Define a rule with an expression string\nrule = Rule('sum(items) > 100 && \"apple\" in items')\n\n# Evaluate the rule against different data contexts\nprint(f\"Result 1: {rule.matches({'items': [10, 20, 30, 40, 50, \"apple\"]})})\")\nprint(f\"Result 2: {rule.matches({'items': [10, 20, \"orange\"]})})\")","lang":"python","description":"This quickstart demonstrates how to create a `Rule` instance with an expression string and then evaluate it against a Python dictionary acting as the data context. The rule expression uses built-in functions like `sum` and logical operators."},"warnings":[{"fix":"Pin your dependency to `rule-engine<5.0.0` to avoid accidental upgrades. Consult the v5 changelog when you're ready to migrate.","message":"Version 5.0.0 is in alpha (v5.0.0a1 has been released) and introduces significant breaking changes and API refactors. Do not update to v5.x without thoroughly reviewing the changelog and migrating your code.","severity":"breaking","affected_versions":"All versions prior to 5.0.0"},{"fix":"Ensure string literals are correctly formatted and custom functions return values compatible with their declared `DataType`.","message":"From v4.5.0 onwards, rule-engine is stricter about invalid string literals and function return types. `StringSyntaxError` is now raised for malformed string literals and `FunctionCallError` for type-incompatible function returns, where previous versions might have had different behavior.","severity":"gotcha","affected_versions":">=4.5.0"},{"fix":"Escape literal backslashes by doubling them: `\"\\\\\"` in the rule string to represent a single backslash.","message":"The backslash character (`\\`) is used for escaping in rule strings. If you need a literal backslash in your rule (e.g., in a regex pattern or string literal), you must double-escape it (e.g., `\\\\`).","severity":"gotcha","affected_versions":"All versions"},{"fix":"Refer to the official documentation on `Context` and `DataType` for defining custom functions and managing evaluation environments effectively.","message":"When defining custom functions or interacting with complex Python objects, ensure you correctly use `Context` and `DataType` objects. Incorrect type declarations or context setup can lead to unexpected `FunctionCallError` or evaluation issues.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[],"ecosystem":"pypi"}