mirror of
https://github.com/ruuda/rcl.git
synced 2025-12-23 04:47:19 +00:00
1.3 KiB
1.3 KiB
Python bindings
RCL includes a Python native module that can be used to load documents, similar
to Python’s built-in json module. Although it is possible to export an
RCL document to JSON and load it using json.load,
there are a few reasons for using the module:
- Avoiding an intermediate file or spawning an additional process.
- Supporting a wider range of types. The module preserves set values and dictionaries with non-string keys.
The name of the module is rcl. See the installation instructions
for how to get the Python module.
Value mapping
RCL values map to the corresponding Python values where possible: strings to strings, dicts to dicts, listst to lists, etc. Other values map as follows:
nullmaps toNone.- Numbers that are integral map to
int. - Numbers that have a decimal point map to
float. - Functions are not supported at this time, they can’t be returned to Python.
load_file
rcl.load_file(path: str) -> Any
Evaluate the RCL expression in the file at the given file path.
loads
rcl.loads(src: str) -> Any
Evaluate the RCL expression src, return the result. This is
analogous to json.loads. TODO: Add a way to control the sandbox policy and
tracer.