Skip to content

Releases: hardbyte/python-common-expression-language

v0.7.0

Choose a tag to compare

@hardbyte hardbyte released this 04 Jul 03:50
bc21129

Python CEL 0.7.0 gives you a much bigger built-in toolbox, lets you call your own functions as methods, and can tell you what an expression uses before you run it β€” on top of a refreshed, more secure Rust core.

✨ What's new

An extended standard library β€” dozens of functions matching Google's cel-go, opt-in via cel.stdlib:

import cel
from cel.stdlib import add_stdlib_to_context

ctx = cel.Context()
add_stdlib_to_context(ctx)

cel.evaluate('"Hello World".lowerAscii()', ctx)   # 'hello world'
cel.evaluate("math.greatest([3, 1, 2])", ctx)     # 3
cel.evaluate("[1, 1, 2, 3].distinct()", ctx)      # [1, 2, 3]
cel.evaluate('base64.encode(b"hi")', ctx)         # 'aGk='

Covers strings, math, sets, encoders and lists helpers (plus bool/dyn/type/min/max). The cel command-line tool enables them automatically.

Call custom functions as methods β€” a function you register works as both f(x) and x.f(y):

ctx = cel.Context()
ctx.add_function("shout", lambda s: s.upper() + "!")
cel.evaluate('"hi".shout()', ctx)   # 'HI!'

Inspect an expression before running it β€” see which variables and functions it references:

program = cel.compile("user.age >= min_age && size(roles) > 0")
program.variables()   # ['min_age', 'roles', 'user']
program.functions()   # ['_&&_', '_>=_', '_>_', 'size']

Handy for validating that your context supplies everything an expression needs, or restricting which names an expression may touch.

⚑ Under the hood

  • Upgraded to cel-rust 0.14 β€” faster and more spec-compliant.
  • Upgraded to PyO3 0.29, which pulls in upstream security fixes.
  • Clearer, more Pythonic error messages (e.g. TypeError: Unsupported operation: string + int).

⚠️ Heads up β€” behaviour changes

These come from cel 0.14 and may affect existing expressions:

  • contains is now string-only. Use the in operator for membership β€” 2 in [1, 2, 3], "key" in myMap β€” or enable the lists extension to get .contains() back for lists and maps.
  • min/max moved into the opt-in cel.stdlib core extension (they used to be always available).
  • Built-in functions take precedence over a custom function registered with the same name.

πŸ“¦ Install / upgrade

pip install --upgrade common-expression-language

See the CHANGELOG for the complete list of changes, and the docs for the new standard-library and introspection reference.

v0.5.6

Choose a tag to compare

@hardbyte hardbyte released this 08 Feb 02:59
9d873f2

What's Changed

  • Fix mapping conversion for dict subclasses by @hardbyte in #29

Full Changelog: v0.5.5...v0.5.6

v0.5.5

Choose a tag to compare

@hardbyte hardbyte released this 07 Feb 08:16

Highlights

  • Upgrade to cel‑rust 0.12.0 (bytes feature enabled)
  • New compile() API + Program.execute() for fast repeated evaluation
  • New OptionalValue wrapper to represent CEL optional values in Python (preserves optional.none() vs optional.of(null))

Added

  • Compile/execute performance benchmark: examples/performance/compile_execute_benchmark.py
  • OptionalValue docs and examples

Notes

  • Optional values now surface as cel.OptionalValue instead of debug strings.
  • Performance guidance updated with compile/execute examples.

New Contributors

Full Changelog: v0.5.3...v0.5.5

v0.5.3: Add substring() function to stdlib and improve logging (#21)

Choose a tag to compare

@hardbyte hardbyte released this 14 Oct 00:28
d18ff9e
  • Added stdlib in Python to add functions before they land upstream. Added substring
  • removed warning level logging in cel crate

v0.5.1

Choose a tag to compare

@hardbyte hardbyte released this 11 Aug 10:27

✨ Added

  • EvaluationMode enum: Control type handling behavior in CEL expressions
    • EvaluationMode.PYTHON (default for Python API): Python-friendly type promotions
    • EvaluationMode.STRICT (default for CLI): Strict CEL type rules with no coercion
  • Type checking support: Added complete type stub files (.pyi) for PyO3 extension

v0.5.0: Release/0.5.0 (#8)

Choose a tag to compare

@hardbyte hardbyte released this 08 Aug 09:18
5f9b38d

🚨 Breaking Changes (Rust API only)

  • Upgraded cel crate (formerly cel-interpreter) 0.10.0 β†’ 0.11.0:
    • Function registration now uses IntoFunction trait.
    • Python integration updated to use Arguments extractor for variadic args.
    • Imports renamed from cel_interpreter:: to cel::.
    • No changes to Python API – all existing code continues to work.

✨ Changed

  • Internal: Refactored Python integration to match new CEL API.
  • Updated dependencies:
    • pyo3: 0.25.0 β†’ 0.25.1
    • pyo3-log: 0.12.1 β†’ 0.12.4

πŸ—’ Maintainer Notes

  • Prepared for upcoming CEL Rust features:
    • Enhanced type system & introspection
    • type() function support
    • Optional value handling

v0.4.1

Choose a tag to compare

@hardbyte hardbyte released this 01 Aug 23:42

Pygments Warning in CLI Fixed

CLI REPL syntax highlighting now works without warnings

v0.4.0

Choose a tag to compare

@hardbyte hardbyte released this 01 Aug 20:53

πŸš€ CLI Interface

  • Command-line tool: cel command now available after installation
  • Interactive REPL: Enhanced terminal experience with syntax highlighting, auto-completion, and command history
  • Multiple output formats: JSON, pretty tables, Python repr, and auto-detection
  • File processing: Batch evaluation of expressions from files
  • Context loading: JSON context files for complex evaluations

Command-line usage

$ cel '1 + 2'                           # β†’ 3
$ cel --interactive                     # Launch REPL
$ cel 'age >= 21' --context user.json  # Context from file

πŸ§ͺ Testing

  • 200+ tests: Complete coverage of all CEL features and edge cases
  • 35 new CLI tests: Formatter, REPL, file operations, and integration testing
  • Performance verification: Microsecond-level evaluation benchmarks
  • Error handling tests: Parser errors, type errors, and edge cases

πŸ”§ Technical Improvements

CEL Interpreter Update

  • cel-interpreter: 0.9.0 β†’ 0.10.0 (enhanced CEL specification compliance)

PyO3 0.25.0 Migration

  • Modern API: Migrated from deprecated IntoPy to IntoPyObject<'py> trait
  • Better error handling: Improved type conversion with proper lifetime management
  • Enhanced type safety: New conversion system with comprehensive error propagation
  • Graceful degradation: Parser panics converted to proper PyValueError exceptions

Documentation

  • Comprehensive Python-facing documentation with examples and type hints
  • Context class: Detailed docstrings for all methods with usage examples

πŸ“¦ Dependencies

  • pyo3: 0.22.6 β†’ 0.25.0
  • cel-interpreter: 0.9.0 β†’ 0.10.0
  • log: 0.4.22 β†’ 0.4.27
  • chrono: 0.4.38 β†’ 0.4.41
  • pyo3-log: 0.11.0 β†’ 0.12.1

Full Changelog: v0.3.1...v0.4.0

v0.3.1

Choose a tag to compare

@hardbyte hardbyte released this 20 Nov 10:51

Bug fix - support None values

v0.3.0

Choose a tag to compare

@hardbyte hardbyte released this 15 Nov 01:47

Adds supports for CEL expressions to use user defined Python Functions.

from cel import evaluate

def is_adult(age):
    return age > 21

evaluate("is_adult(age)", {'is_adult': is_adult, 'age': 18})
# False

Also updates pyo3 and cel-interpreter to latest stable versions.