gresb_cel_python
This project is not ready for production yet.
Parser and evaluator for CEL in Python using ANTLR4
This library provides parser and evaluator for Common Expression Language (CEL) expressions in Python projects. CEL is a language developed by Google that allows for safe and fast evaluation of expressions in a wide variety of applications, such as policy engines, rule engines, and more.
Features
Parse and evaluate CEL expressions directly within TypeScript projects.
Support for common arithmetic operations, logical operations, and comparisons.
Extensible design for adding custom functions and variables.
Error handling during parsing with custom error listeners.
Context-based evaluation to support dynamic expression evaluation.
Installation
You can install gresb_cel_python via pip:
pip install gresb_cel_python
Usage
Evaluate expression
To use the CEL parser and evaluator, you can instantiate the Runtime class with a CEL expression, and then evaluate it with a given context.
from gresb_cel_pyhon import Runtime
# Define a CEL expression
expression = "a + b * 10"
# Create a Runtime instance with the expression
runtime = Runtime(expression)
# Define a context with variables
context = {
"a": 5,
"b": 3
}
# Evaluate the expression with the context
result = runtime.evaluate(context)
print(f"Result: {result}") # Output: Result: 35
Parsing Valiation
from cel_in_py import Runtime
# Define a CEL expression
expression = "a + b * 10"
# Create a Runtime instance with the expression
runtime = Runtime(expression)
# Define a context with variables
context = {
"a": 5,
"b": 3
}
# Evaluate the expression with the context
result = runtime.evaluate(context)
print(f"Result: {result}") # Output: Result: 35
Advanced Usage
The VisitorInterp class allows for extending the functionality by adding custom functions or modifying the evaluation logic.
from cel_in_py.visitor_interp import VisitorInterp
# Define a custom function
def custom_function(x):
return x * x
# Extend the visitor with the custom function
class CustomVisitor(VisitorInterp):
def __init__(self, context):
super().__init__(context)
self.function_registry["custom_function"] = custom_function
# Use the custom visitor in the runtime
expression = "custom_function(5)"
runtime = Runtime(expression)
visitor = CustomVisitor({})
result = visitor.visit(runtime.ast)
print(f"Result: {result}") # Output: Result: 25
Metadata
Release files for gresb-cel-python 0.0.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| gresb_cel_python-0.0.3.tar.gz | 54.3 kB | Without provenance | Details for gresb_cel_python-0.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gresb_cel_python-0.0.3-py3-none-any.whl | Python 3 | none | any | Details for gresb_cel_python-0.0.3-py3-none-any.whl |
Total release size: 111.6 kB
Release files / gresb_cel_python-0.0.3.tar.gz
| Download URL | gresb_cel_python-0.0.3.tar.gz |
|---|---|
| Size | 54.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b89a51343736afd9734c5d7d5b3ac8528a6cc1217e854f393f573895d78bcf96
|
|
BLAKE2b-256 checksum How to use checksums |
33aef1c63e8c0e70a1ba60d31391c2f9768f9a36bdd9d161e709bb1ddfd85e49
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Release files / gresb_cel_python-0.0.3-py3-none-any.whl
| Download URL | gresb_cel_python-0.0.3-py3-none-any.whl |
|---|---|
| Size | 57.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c4f7476dff2a8e71760c9805c27864bd78db867b0a21311ba29d2844e9a33a11
|
|
BLAKE2b-256 checksum How to use checksums |
fbe2d67648b2856e54f6cfd11244ef92457450e5432c4257a4a379bc8a64ef93
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/5.1.0 CPython/3.12.4
|
Security for gresb-cel-python 0.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.