Registry / auth-security / cel-python

cel-python

JSON →
library0.5.0pypypi✓ verified 23d ago

cel-python is a pure Python implementation of Google's Common Expression Language (CEL), currently at version 0.5.0. It provides common semantics for expression evaluation, enabling applications to interoperate through a fast, embeddable expression language. The library aims for minimal dependencies and is primarily used for security policies, such as within Cloud Custodian. Its release cadence is tied to its primary consumers.

pip install cel-python
INSTALL
IMPORT
SIG · CEL-PYTHON
C
cel-python
auth-securitypythonv0.5.0
Install
2.4s avg
Import
230ms
Disk
28MB
Pass rate
4/ 10
Env Coverage4 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.5.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
glibc
py 3.10
✕ build_error
✓ 2.5s
py 3.11
✕ build_error
✓ 2.5s
py 3.12
✕ build_error
✓ 2.3s
py 3.13
✕ build_error
✓ 2.3s
py 3.9
✕ build_error
✕ build_error
28MB installed
● package 28MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Environment
from celpy import Environment
from celpy.evaluation import Environment
While Environment is in evaluation, it's exposed directly via celpy top-level for convenience.
celtypes
from celpy import celtypes
import celtypes
celtypes is a module within the celpy package, not a top-level module.

This example demonstrates compiling and evaluating a simple CEL expression with a string variable, using the Environment and celtypes classes.

from celpy import Environment, celtypes decls = {"name": celtypes.StringType} env = Environment(annotations=decls) ast = env.compile("'Hello world! I\'m " + name + ".'") out = env.program(ast).evaluate({"name": "CEL"}) print(out) # Expected: Hello world! I'm CEL.
Debug
Known issues
gotchaCEL's type semantics differ from native Python, and type coercion is generally not performed implicitly. This can lead to unexpected `TypeError`s if not handled explicitly in expressions.
fix
Ensure explicit type conversion within CEL expressions (e.g., `double(1) + 2.5` instead of `1 + 2.5`) if mixed types are intended, or ensure consistent typing of inputs.
affects: All versions
gotchaDivision behavior (`/`) in CEL truncates towards zero, which is different from Python's integer division (`//`) that truncates towards negative infinity. This can lead to subtle differences in arithmetic results.
fix
Be aware of the truncation behavior for division operations and test expressions thoroughly, especially with negative numbers.
affects: All versions
gotchaCEL runtime errors are mapped to Python exceptions, specifically `celpy.evaluation.EvalError`. These errors provide a message similar to the CEL error, along with an underlying Python exception.
fix
Implement proper try-except blocks to catch `celpy.evaluation.EvalError` when evaluating expressions to handle potential runtime issues gracefully.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'celpy'
The 'cel-python' library's main package, 'celpy', is not installed in the current Python environment or is incorrectly imported.
fix
Install the library using pip: `pip install cel-python`. Ensure imports are `import celpy` or `from celpy import ...`.
celpy.evaluation.EvalError: undeclared reference to 'variable_name'
The CEL expression refers to a variable or function identifier that has not been declared in the `celpy.Environment` or provided in the `activation` dictionary during evaluation.
fix
Ensure all variables and functions used in the CEL expression are either provided in the `activation` dictionary passed to `evaluate()` or explicitly declared in the `celpy.Environment` configuration.
celpy.evaluation.EvalError: no_matching_overload: function_name
A function in the CEL expression was called with arguments of incompatible types or an incorrect number of arguments, for which no matching overload exists.
fix
Adjust the types of the arguments in the CEL expression to match an available function overload, or define a custom function binding in the `celpy.Environment` that supports the desired argument types.
ValueError: Failed to parse expression 'invalid syntax...'
The provided CEL expression string contains a syntax error, meaning it does not conform to the Common Expression Language grammar.
fix
Carefully review the CEL expression for typos, missing operators, unmatched parentheses, or other grammatical mistakes.
Upgrade
Version history
0.5.0latest on PyPI · released Jan 31, 2026
Audit
Dependencies
re2requiredUsed for regular expression evaluation as specified by CEL.
Agent activity
29 hits · last 30 days
node
25
OpenAI (training)
1
Resources
cel-python — pip install cel-python · libregistry