{"id":19729513,"url":"https://github.com/cloud-custodian/cel-python","last_synced_at":"2025-04-08T01:38:02.530Z","repository":{"id":37050605,"uuid":"272774581","full_name":"cloud-custodian/cel-python","owner":"cloud-custodian","description":"Pure Python implementation of the Common Expression Language","archived":false,"fork":false,"pushed_at":"2025-03-06T05:05:06.000Z","size":699,"stargazers_count":124,"open_issues_count":25,"forks_count":23,"subscribers_count":10,"default_branch":"main","last_synced_at":"2025-04-01T00:37:17.317Z","etag":null,"topics":["cel","cloud","python3","rules-engine"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/cloud-custodian.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-06-16T17:45:35.000Z","updated_at":"2025-03-31T07:08:21.000Z","dependencies_parsed_at":"2024-05-20T22:22:45.070Z","dependency_job_id":"eac4abfb-67f1-453d-b5a1-ee9e30145e7a","html_url":"https://github.com/cloud-custodian/cel-python","commit_stats":{"total_commits":81,"total_committers":8,"mean_commits":10.125,"dds":0.4814814814814815,"last_synced_commit":"6631083ba76e6b267323b35fb2f020611f01f467"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloud-custodian%2Fcel-python","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloud-custodian%2Fcel-python/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloud-custodian%2Fcel-python/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/cloud-custodian%2Fcel-python/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/cloud-custodian","download_url":"https://codeload.github.com/cloud-custodian/cel-python/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247761052,"owners_count":20991532,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cel","cloud","python3","rules-engine"],"created_at":"2024-11-12T00:12:42.070Z","updated_at":"2025-04-08T01:38:02.507Z","avatar_url":"https://github.com/cloud-custodian.png","language":"Python","readme":"##########\ncel-python\n##########\n\n..  image:: https://img.shields.io/pypi/v/cel-python.svg\n    :target: https://pypi.org/projects/cel-python/\n    :alt: PyPI: cel-python\n\n..  image:: https://github.com/cloud-custodian/cel-python/workflows/CI/badge.svg\n    :target: https://github.com/cloud-custodian/cel-python/actions\n    :alt: GitHub Actions Build Status\n\n..  image:: https://img.shields.io/badge/license-Apache%202-blue.svg\n    :target: https://www.apache.org/licenses/LICENSE-2.0\n    :alt: Apache License\n\nPure Python implementation of Google Common Expression Language, https://opensource.google/projects/cel.\n\n    The Common Expression Language (CEL) implements common semantics for expression evaluation,\n    enabling different applications to more easily interoperate.\n\n    Key Applications\n\n    Security policy: organization have complex infrastructure and need common tooling to reason about the system as a whole\n\n    Protocols: expressions are a useful data type and require interoperability across programming languages and platforms.\n\nThis implementation has minimal dependencies, runs quickly, and can be embedded into Python-based applications.\nSpecifically, the intent is to be part of Cloud Custodian, C7N, as part of the security policy filter.\n\nInstallation\n=============\n\n::\n\n    pip install cel-python\n\nYou now have the CEL run-time available to Python-based applications.\n\nCommand Line\n============\n\nWe can read JSON directly from stdin, making this a bit like ``jq``.\n\n::\n\n    % python -m celpy '.this.from.json * 3 + 3' \u003c\u003cEOF\n    heredoc\u003e {\"this\": {\"from\": {\"json\": 13}}}\n    heredoc\u003e EOF\n    42\n\n\nIt's also a desk calculator, like ``expr``, but with float values:\n\n::\n\n    % python -m celpy -n '355.0 / 113.0'\n    3.1415929203539825\n\nIt's not as sophistcated as ``bc``.\nBut, yes, this has a tiny advantage over ``python -c '355/113'``. Most notably, the ability\nto embed Google CEL into other contexts where you don't *really* want Python's power.\n\nIt's also capable of decision-making, like ``test``:\n\n::\n\n    % echo '{\"status\": 3}' | python -m celpy -sb '.status == 0'\n    false\n    % echo $?\n    1\n\nWe can provide a ``-a`` option to define objects with specific data types.\nThis is particularly helpful for providing protobuf message definitions.\n\n::\n\n    python -m celpy -n --arg x:int=6 --arg y:int=7 'x*y'\n    42\n\nIf you want to see details of evaluation, use ``-v``.\n\n::\n\n    python -m celpy -v -n '[2, 4, 6].map(n, n/2)'\n    ... a lot of output\n    [1, 2, 3]\n\nLibrary\n=======\n\nTo follow the pattern defined in the Go implementation, there's a multi-step\nprocess for compiling a CEL expression to create a runnable \"program\". This program\ncan then be applied to argument values.\n\n::\n\n    \u003e\u003e\u003e import celpy\n    \u003e\u003e\u003e cel_source = \"\"\"\n    ... account.balance \u003e= transaction.withdrawal\n    ... || (account.overdraftProtection\n    ... \u0026\u0026 account.overdraftLimit \u003e= transaction.withdrawal - account.balance)\n    ... \"\"\"\n\n    \u003e\u003e\u003e env = celpy.Environment()\n    \u003e\u003e\u003e ast = env.compile(cel_source)\n    \u003e\u003e\u003e prgm = env.program(ast)\n\n    \u003e\u003e\u003e activation = {\n    ...     \"account\": celpy.json_to_cel({\"balance\": 500, \"overdraftProtection\": False}),\n    ...     \"transaction\": celpy.json_to_cel({\"withdrawal\": 600})\n    ... }\n    \u003e\u003e\u003e result = prgm.evaluate(activation)\n    \u003e\u003e\u003e result\n    BoolType(False)\n\nThe Python classes are generally based on the object model in https://github.com/google/cel-go\nThese types semantics are slightly different from Python's native semantics.\nType coercion is not generally done.\nPython ``//`` truncates toward negative infinity. Go (and CEL) ``/`` truncates toward zero.\n\n\nDevelopment\n===========\n\nThe parser is based on the grammars used by Go and C++, but processed through Python Lark.\n\nSee https://github.com/google/cel-spec/blob/master/doc/langdef.md\n\nhttps://github.com/google/cel-cpp/blob/master/parser/Cel.g4\n\nhttps://github.com/google/cel-go/blob/master/parser/gen/CEL.g4\n\nNotes\n=====\n\n\nCEL provides a number of runtime errors that are mapped to Python exceptions.\n\n- ``no_matching_overload``: this function has no overload for the types of the arguments.\n- ``no_such_field``: a map or message does not contain the desired field.\n- ``return error for overflow``: integer arithmetic overflows\n\nThere are mapped to Python ``celpy.evaluation.EvalError`` exception. The args will have\na message similar to the CEL error message, as well as an underlying Python exception.\n\nIn principle CEL can pre-check types.\nHowever, see https://github.com/google/cel-spec/blob/master/doc/langdef.md#gradual-type-checking.\nRather than try to pre-check types, we'll rely on Python's implementation.\n\n\nContributing\n============\n\nSee https://cloudcustodian.io/docs/contribute.html\n\n\nCode of Conduct\n===============\n\nThis project adheres to the `Open Code of Conduct \u003chttps://developer.capitalone.com/resources/code-of-conduct\u003e`_. By\nparticipating, you are expected to honor this code.\n","funding_links":[],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloud-custodian%2Fcel-python","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcloud-custodian%2Fcel-python","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloud-custodian%2Fcel-python/lists"}