Google、Python向け共通式言語をオープンソース化
Googleは、シンプルさ、速度、安全性、移植性を設計思想とする非チューリング完全な組み込みポリシー・式言語「Common Expression Language (CEL)」のPython実装「CEL-expr-python」をオープンソース化した。
キーポイント
GoogleによるCELのPython実装のオープンソース化
GoogleがCommon Expression Language (CEL)のPython実装「CEL-expr-python」をオープンソースとして公開した。
CELの設計思想と特徴
CELは非チューリング完全な言語であり、シンプルさ、速度、安全性、移植性を重視して設計されている。
主な用途
組み込みポリシーや式の記述に特化した言語として、設定やルールの評価などでの利用が想定される。
影響分析・編集コメントを表示
影響分析
このリリースにより、Pythonエコシステム内で安全でポータブルなポリシー記述・評価の選択肢が増える。特にクラウド設定やリソース管理ポリシーなど、Google Cloudを中心とした環境での実用性が高まる可能性があるが、業界全体を変革するほどの革新性は限定的である。
編集コメント
Googleのクラウド・セキュリティ関連ツールチェーンの一環としてのリリースと捉えられる。開発者にとっては実用的なツールが増えたという点で価値があるが、技術的に画期的なニュースというよりはエコシステムの充実を示すアップデートと言える。
Google は、Common Expression Language (CEL) の Python 実装である CEL-expr-python をオープンソース化しました。CEL は、シンプルさ、速度、安全性、移植性を目的として設計された、非チューリング完全な埋め込み型ポリシーおよび式言語です。
Google によると、「CEL は、ポリシーの適用、データ検証、動的設定などのアプリケーションにおいて普及した技術となっています」。今回のリリースにより公式にメンテナンスされる実装が提供され、インフラストラクチャとアプリケーション全体で CEL を一貫して使用しやすくなりました。その結果、Python 開発者はコミュニティサポートによるライブラリに依存するのではなく、ファーストパーティの CEL ランタイムを利用できるようになりました。
CEL チームは、CEL のセマンティクスとの最大限の一貫性を確保しつつ、Python ユーザーがこの本番環境対応のコア上に直接 Python で拡張や機能強化を行えるようにするため、公式の C++ 実装をラップして CEL-expr-python を開発することを選択しました。
公式の C++ 実装をラップするもう一つの利点は、新機能や最適化を含む C++ コアの将来の改善が、自動的に CEL-expr-python に継承されることです。
以下のスニペットは、CEL-expr-python を初期化して式を評価する方法を示しています:
from cel_expr_python import cel
変数の定義
cel_env = cel.NewEnv(variables={"who": cel.Type.STRING})
expr = cel_env.compile("'Hello, ' + who + '!'")
コンパイルされた式の評価と出力
print(expr.eval(data={"who": "World"})) // Hello, World!
Reddit でコメントしたユーザー rabornkraken は、式をコンパイルしてリクエスト間で再利用できる機能が CEL を魅力的にしている点だと指摘しました:
私は機能フラグのためにアドホックな AST 評価器を使用してきましたが、メンテナンスが非常に困難です。式がランタイムで実際にサポートされている内容からずれてしまうからです。適切な型チェック付きのコンパイルステップがあれば、多くの問題を事前に検出できるはずです。
プロジェクトメンテナの一人である TristonianJones は、CEL が特に輝くシナリオについて詳しく説明しました:
これはより大きなポリシーや設定フォーマットに埋め込むのに非常に適しており、github.com/google/cel-go リポジトリにはポリシー作成と組み合わせのためのより広範なツールチェーンがあります。しかし、素晴らしい点は、Go (または Java) ツールチェーンを使用してコンパイルし、Python で簡単に評価できることです。
Common Expression Language は Google によって設計されたもので、Kubernetes や Envoy などの高性能アプリケーションにおける条件やルールの評価のために高速、移植可能、安全であるように作られています。C ライクな構文を使用し、「一度コンパイルして多数回評価」という特徴を持つため、高速で安全かつ柔軟なポリシー評価を必要とするシステムへの埋め込みに最適です。
CEL はチューリング完全ではなく、副作用がなく、必ず終了することが保証されているため、ポリシー適用、データ検証、動的設定、ユーザー入力や設定からのランタイムルールを含む、安全な組み込みルール評価に理想的です。また、「ナノ秒からマイクロ秒」レベルの非常に高速な評価も提供します。
CEL-expr-python は GitHub で利用可能であり、Google では codelab を通じて包括的なチュートリアルも提供しています。
About the Author
Sergio De Simone
Sergio De Simone はソフトウェアエンジニアです。Sergio は過去 25 年以上にわたり、Siemens、HP、そして小規模なスタートアップなど、多様なプロジェクトや企業でソフトウェアエンジニアとして活動してきました。特に最近の 10 年以上は、モバイルプラットフォームおよび関連技術の開発に注力しています。現在では BigML, Inc. で勤務し、iOS および macOS の開発を率いています。
Show moreShow less
原文を表示
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 in high-performance applications such as 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.
About the Author
Sergio De Simone
Sergio De Simone is a software engineer. Sergio has been working as a software engineer for over twenty five years across a range of different projects and companies, including such different work environments as Siemens, HP, and small startups. For the last 10+ years, his focus has been on development for mobile platforms and related technologies. He is currently working for BigML, Inc., where he leads iOS and macOS development.
Show moreShow less
関連記事
今日のまとめ
AI日報で今日の重要ニュースをまとめ読み