Pure Python Common Expression Language (CEL)

0.5.0 · active · verified Fri Apr 10

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.

Warnings

Install

Imports

Quickstart

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.

view raw JSON →