PyVRL: Python Interface for Vector Remap Language (VRL)
PyVRL is a Python library that allows you to execute Vector Remap Language (VRL) transformations directly within your Python applications. It provides bindings to the VRL compiler and runtime, enabling data manipulation, filtering, and routing with VRL expressions. The current version is 0.0.2, indicating it's in very early development with an irregular release cadence.
Common errors
-
TypeError: expected pyvrl.value.Value, got dict
cause You are passing a standard Python dictionary or list directly to a `pyvrl` function (e.g., `compiled_program.run()`) that expects a `pyvrl.value.Value` object.fixWrap your Python data in a `Value` object: `compiled_program.run(Value({'key': 'value'}))` -
pyvrl.compiler.VRLCompilationError: ... (followed by VRL specific error details)
cause The VRL expression provided to `VRLCompiler().compile()` contains a syntax or semantic error according to VRL rules.fixCarefully review your VRL expression for correctness. Common errors include missing dots for field access (`.field`), incorrect function names, or mismatched parentheses. Consult VRL documentation.
Warnings
- breaking As a library in early development (version 0.0.x), the API is subject to frequent and potentially breaking changes. Stability is not guaranteed between minor or even patch versions.
- gotcha VRL expressions in `pyvrl` operate on `pyvrl.value.Value` objects, not standard Python dictionaries or lists directly. Passing raw Python types where a `Value` is expected will result in type errors.
- gotcha VRL syntax errors are caught by the `VRLCompiler` during the `compile()` step, not by Python's interpreter. Invalid VRL expressions will lead to `pyvrl.compiler.VRLCompilationError` at runtime.
Install
-
pip install pyvrl
Imports
- VRLCompiler
from pyvrl.compiler import VRLCompiler
- Value
from pyvrl import Value
from pyvrl.value import Value
Quickstart
from pyvrl.compiler import VRLCompiler
from pyvrl.value import Value
# Initialize the VRL compiler
compiler = VRLCompiler()
# Compile a VRL program to uppercase the 'message' field
vrl_program = '.message = upcase(.message)'
compiled_program = compiler.compile(vrl_program)
# Prepare input data as a pyvrl.value.Value object
input_data = Value({"message": "hello world"})
# Run the VRL program
output_data = compiled_program.run(input_data)
# Convert the output back to a Python dictionary
result = output_data.as_python()
print(f"Input: {input_data.as_python()}")
print(f"Output: {result}")
# Expected output: {'message': 'HELLO WORLD'}