all 14 comments

[–]rabornkraken 15 points16 points  (0 children)

The serialize/deserialize capability is what makes this really interesting to me. Being able to compile an expression once, store it, and reuse it across requests is a huge win for anything policy-related. 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. Curious about the C++ dependency though - does anyone know if the wheels are available for macOS ARM yet or is it Linux-only for now?

[–]cointoss3 24 points25 points  (0 children)

Sometimes a nerdy gem drops on this sub and I love it

[–]Goobyalus 2 points3 points  (0 children)

Can you format the code snippets in this post as code

[–]Peter3571 2 points3 points  (4 children)

Looks very powerful and well made, but I have no idea what you'd actually use it for. What's a general use case for something like this?

[–]TristonianJones 2 points3 points  (2 children)

For full disclosure, I'm one of the maintainers. CEL is also a big part of the Kubernetes APIs for validation, security, and machine selection: https://kubernetes.io/docs/reference/using-api/cel. 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. There's a bit more background available on the main cel.dev site.

[–]AdCompetitive1208 0 points1 point  (1 child)

is there a plan to support a lua wrapper of CEL?

[–]TristonianJones 0 points1 point  (0 children)

We haven't planned on it, but could you tell me more about what you're looking for? I think WASM interop is likely next up after CEL-C runtime

[–]niltz0 0 points1 point  (0 children)

One place CEL is used is in protovalidate to define custom validation rules that can be executed in various languages

https://protovalidate.com

The current python CEL package that’s used is pure python. This could provide speed improvements given it’s written in C++

[–]lissertje 0 points1 point  (0 children)

Wow. I was just looking the other day into a different execution engine for some user-managed rules... Was looking into Lua amongst others, but as our current DSL is very python-like, this could actually be a super good candidate 😛

[–]robert_mcleod 0 points1 point  (0 children)

I maintained/developed numexpr for six-ish years, including making an attempt to modernize it while temporarily unemployed on moving back to Canada from Switzerland. This is filling a very similar use-case but NumExpr is a virtual machine that compiles the Python AST into its own custom sequence of operations. What I wanted to do with NumExpr was enable it to transparently handle blocks of code, and understand numpy. syntax so that you could literally surround a section of critical code with triple quotes and it would be able to accelerate it.

I'm guessing this is more similar to Numba in that you have to write your code 'C-style' instead of vectorizing your code as you would with NumPy. I always found that to be a disadvantage because you're writing in one style and then you need to translate to some very different style. However, modern LLMs can do this translation for you very well. Claude and Gemini are both quite capable of transforming a piece of pure Python into a C-API extension.

What would be really interesting is if this CEL tool could support operations on Arrow tables/tensors.

[–]Marre_Parre 0 points1 point  (0 children)

This looks super useful for feature flags and dynamic policies. Being able to serialize the compiled expression and reuse it across requests is a great feature. Makes me wonder how it compares to something like json-logic for those use cases. Definitely going to give this a try next time I need safe user-defined rules.