跳转到主要内容

未提供项目描述

项目描述

通用表达式语言 (CEL)

通用表达式语言 (CEL) 是一种非图灵完备的语言,旨在实现简单性、速度和安全。CEL 主要用于在多种应用程序中评估表达式,例如策略评估、状态机转换和图遍历。

此 Python 包封装了 Rust 实现 cel-interpreter

基本用法

from cel import evaluate
expression = "age > 21"
result = evaluate(expression, {"age": 18})
print(result)  # False

只需将 CEL 表达式和上下文字典传递给 evaluate 函数。函数返回表达式评估的结果,并将其转换为 Python 原始类型。

CEL 支持各种运算符、函数和类型

evaluate(
    'resource.name.startsWith("/groups/" + claim.group)', 
    {
        "resource": {"name": "/groups/hardbyte"},
        "claim": {"group": "hardbyte"}
    }
)

未来工作

支持将 Python datetime 对象和 timedeltas 转换为 CEL 类型。

命令行界面

该包(计划)还提供命令行界面以评估 CEL 表达式

$ python -m cel '1 + 2'
3

自定义 Python 函数

能够将 Python 函数添加到上下文对象

from cel import evaluate, Context

def is_adult(age):
    return age > 21

context = Context()
context.add_function("is_adult", is_adult)
print(evaluate("is_adult(age)", {"age": 18}, context))  # False

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于 安装软件包 的信息。

源代码分发

common_expression_language-0.1.1.tar.gz (17.5 kB 查看散列值)

上传时间: 源代码

构建分发

common_expression_language-0.1.1-cp312-none-win_amd64.whl (907.5 kB 查看哈希值)

上传时间 CPython 3.12 Windows x86-64

common_expression_language-0.1.1-cp312-none-win32.whl (823.3 kB 查看哈希值)

上传时间 CPython 3.12 Windows x86

common_expression_language-0.1.1-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.0 MB 查看哈希值)

上传时间 CPython 3.12 manylinux: glibc 2.17+ x86-64

common_expression_language-0.1.1-cp312-cp312-manylinux_2_17_s390x.manylinux2014_s390x.whl (2.2 MB 查看哈希值)

上传时间 CPython 3.12 manylinux: glibc 2.17+ s390x

common_expression_language-0.1.1-cp312-cp312-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (2.3 MB 查看哈希值)

上传时间 CPython 3.12 manylinux: glibc 2.17+ ppc64le

common_expression_language-0.1.1-cp312-cp312-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.9 MB 查看哈希值)

上传时间 CPython 3.12 manylinux: glibc 2.17+ ARMv7l

common_expression_language-0.1.1-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.9 MB 查看哈希值)

上传时间 CPython 3.12 manylinux: glibc 2.17+ ARM64

common_expression_language-0.1.1-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.whl (2.0 MB 查看哈希值)

上传时间 CPython 3.12 manylinux: glibc 2.5+ i686

common_expression_language-0.1.1-cp312-cp312-macosx_11_0_arm64.whl (1.0 MB 查看哈希值)

上传时间 CPython 3.12 macOS 11.0+ ARM64

common_expression_language-0.1.1-cp312-cp312-macosx_10_12_x86_64.whl (1.1 MB 查看哈希值)

上传于 CPython 3.12 macOS 10.12+ x86-64

common_expression_language-0.1.1-cp311-none-win_amd64.whl (906.7 kB 查看哈希值)

上传于 CPython 3.11 Windows x86-64

common_expression_language-0.1.1-cp311-none-win32.whl (822.1 kB 查看哈希值)

上传于 CPython 3.11 Windows x86

common_expression_language-0.1.1-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.0 MB 查看哈希值)

上传于 CPython 3.11 manylinux: glibc 2.17+ x86-64

common_expression_language-0.1.1-cp311-cp311-manylinux_2_17_s390x.manylinux2014_s390x.whl (2.2 MB 查看哈希值)

上传于 CPython 3.11 manylinux: glibc 2.17+ s390x

common_expression_language-0.1.1-cp311-cp311-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (2.3 MB 查看哈希值)

上传于 CPython 3.11 manylinux: glibc 2.17+ ppc64le

common_expression_language-0.1.1-cp311-cp311-manylinux_2_17_armv7l.manylinux2014_armv7l.whl (1.9 MB 查看哈希值)

上传于 CPython 3.11 manylinux: glibc 2.17+ ARMv7l

common_expression_language-0.1.1-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (1.9 MB 查看哈希值)

上传于 CPython 3.11 manylinux: glibc 2.17+ ARM64

common_expression_language-0.1.1-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.whl (2.0 MB 查看哈希值)

上传于 CPython 3.11 manylinux: glibc 2.5+ i686

common_expression_language-0.1.1-cp311-cp311-macosx_11_0_arm64.whl (1.0 MB 查看哈希值)

上传于 CPython 3.11 macOS 11.0+ ARM64

common_expression_language-0.1.1-cp311-cp311-macosx_10_12_x86_64.whl (1.1 MB 查看哈希值)

上传于 CPython 3.11 macOS 10.12+ x86-64

支持者

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误记录 StatusPage StatusPage 状态页