Google has open sourced CEL-expr-python, a Python implementation of the Common Expression Language (CEL), a non-Turing complete embedded policy and expression language designed for simplicity, speed, safety, and portability.
Google says that “CEL has become a prevalent technology for applications like policy enforcement, data validation, and dynamic configuration”. This release provides an officially maintained implementation, making it easier to use CEL consistently across infrastructure and applications. As a result, Python developers now have a first-party CEL runtime instead of relying on community-supported libraries.
The CEL team has chosen to develop CEL-expr-python by wrapping our official C++ implementation to ensure maximum consistency with CEL semantics while enabling Python users to extend and enrich the experience on top of this production-ready core in Python directly.
Another advantage of wrapping the official C++ implementation is that any future improvements to the C++ core, including new features and optimizations, will automatically be inherited by CEL-expr-python.
The following snippet shows how you can initialize CEL-expr-python to evaluate an expression:
from cel_expr_python import cel
# Define variables
cel_env = cel.NewEnv(variables={"who": cel.Type.STRING})
expr = cel_env.compile("'Hello, ' + who + '!'")
# Evaluate and print the compiled expression
print(expr.eval(data={"who": "World"}))) // Hello, World!
Commenting on Reddit, user rabornkraken noted that the ability to compile an expression and reuse it across requests is what makes CEL interesting:
I have been using ad-hoc AST evaluators for feature flags and they are painful to maintain – the expressions drift from what the runtime actually supports. Having a proper type-checked compile step would catch so many issues upfront.
TristonianJones, one of the project maintainers, elaborated on scenarios where CEL really shines:
It’s pretty good for embedding into a larger policy or configuration format and we have more extensive toolchains for policy authoring and composition in our github.com/google/cel-go repository, but the nice part is you could compile using the Go (or Java) toolchain and evaluate in Python pretty easily.
The Common Expression Language was designed by Google to be fast, portable, and safe for evaluating conditions and rules, especially within high-performance applications like Kubernetes and Envoy. It uses C-like syntax and is “compile-once, evaluate-many,” making it perfect for embedding in systems requiring fast, secure, and flexible policy evaluation.
CEL is non-Turing complete, side-effect free, and guaranteed to terminate, which makes it ideal for safe embedded rule evaluation, including policy enforcement, data validation, dynamic configuration, and runtime rules from user input or config. It also provides very fast evaluation, “from nanoseconds to microseconds”.
CEL-expr-python is available on GitHub, and Google also provides a comprehensive tutorial via codelab.
