QCL provides Python bindings via PyO3 and maturin.
pip install maturin# Into the active virtualenv (development):
make python
# or directly:
maturin develop --features python --release
# Build a distributable wheel:
maturin build --features python --release
# wheel is written to target/wheels/Evaluate a QCL expression against a Python dict. Returns a native Python value.
import qcl
result = qcl.eval("@x + 1", {"x": 2})
assert result == 3
result = qcl.eval("@req.user.role", {"req": {"user": {"role": "admin"}}})
assert result == "admin"Same as eval, but accepts a JSON string as context.
import qcl
result = qcl.eval_json("@name", '{"name": "alice"}')
assert result == "alice"Return True if the expression result is truthy, False otherwise.
import qcl
assert qcl.check("@role == 'admin'", {"role": "admin"}) is True
assert qcl.check("@role == 'admin'", {"role": "user"}) is False| Python | QCL Val |
|---|---|
None |
Nil |
bool |
Bool |
int |
Int |
float |
Float |
str |
Str |
list |
List |
dict (string keys) |
Map |
All functions raise ValueError on parse or evaluation errors:
import qcl
try:
qcl.eval("@x +", {"x": 1})
except ValueError as e:
print(f"Error: {e}")