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.1-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.1-cp39-abi3-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for python_cel-0.1.1-cp39-abi3-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 f7ffaa78a0e6482b83a8d8545453b600d32cdffb3005284be11aa82c97c15dcc
MD5 a216d2f5e8f96ad76be573509be67232
BLAKE2b-256 d3a79e965f256d58570ad433088a91d55f0e9bc657f26767511dfa9fcf2542fb

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