Skip to main content

Python bindings for the cel-rust crate

Project description

Python CEL

PyPI - Python Version PyPI - Version

Python CEL are Python bindings for the Common Expression Language (CEL) rust implementation found here. CEL is a language designed to allow non-sandboxed evaluation of expressions and scripts.

Features

  • Written in Rust: The underlying library and bindings are written in Rust, which makes it fast and memory-efficient.
  • Safe: The Rust implementation is memory-safe and thread-safe.
  • Extensible: The library is designed to be easily extensible with custom functions and variables.

Quick Start

Installation

pip install python-cel

Basic Usage

from cel import Context, Program, evaluate_expression

# Quickly evaluate an expression
result = evaluate_expression("1 + 2")
print(result)  # 3

result = evaluate_expression("x + y", variables={"x": 1, "y": 3})
print(result)  # 4

result = evaluate_expression("add_nums(1, 2)", functions={"add_nums": lambda x, y: x + y})
print(result)  # 3

# Manually create a context and program
context = Context()
context.add_variables({"x": 1, "y": 2})
context.add_functions({"add_nums": lambda x, y: x + y})

# OR
context = Context(
    variables={"x": 1, "y": 2},
    functions={"add_nums": lambda x, y: x + y}
)

program = Program("add_nums(x, y)")
result = program.evaluate(context)
print(result)  # 3

License

This project is licensed under MIT License.

Support & Feedback

If you encounter any issues or have feedback, please open an issue. We'd love to hear from you!

Made with ❤️ by Emergent Methods

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_cel-0.1.0-cp39-abi3-manylinux_2_34_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.9+manylinux: glibc 2.34+ x86-64

File details

Details for the file python_cel-0.1.0-cp39-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for python_cel-0.1.0-cp39-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 04b3a64c2ace6458738a31e1d2403d68cb8f48ae5257f8c613ee39378dfdecfe
MD5 300b5e033a15e31d79a8f3b4b331c1c0
BLAKE2b-256 f640c0274c51669834804537d32d227231287d43061e8929e38572b3f9408381

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page