rcl/docs/python_bindings.md
2025-08-30 11:06:35 +02:00

39 lines
1.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Python bindings
RCL includes a Python native module that can be used to load documents, similar
to Pythons built-in `json` module. Although it is possible to export an
<abbr>RCL</abbr> document to <abbr>JSON</abbr> 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][install]
for how to get the Python module.
[install]: installation.md#python-module-from-source
## 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:
* `null` maps to `None`.
* Numbers that are integral map to `int`.
* Numbers that have a decimal point map to `float`.
* Functions are not supported at this time, they cant be returned to Python.
## load_file
rcl.load_file(path: str) -> Any
Evaluate the <abbr>RCL</abbr> expression in the file at the given file path.
## loads
rcl.loads(src: str) -> Any
Evaluate the <abbr>RCL</abbr> expression `src`, return the result. This is
analogous to `json.loads`. TODO: Add a way to control the sandbox policy and
tracer.