Click here for information about the luxem format.
An interface similar to Python's json module is provided with functions load, loads, dump and dumps. Reader and Writer provide the core functionality.
Table of contents:
import luxem tree = luxem.loads(b'{a: 1, b: (int) 2}')[0] print(tree['b'].name) > 'int' print(tree['b'].value) > '2' data = luxem.dumps({'a': [1, 2, 3], 'b': luxem.Typed('int', 4)}, pretty=True) print(data) > { > a: [ > 1, > 2, > 3, > ], > b: (int) 4, > },
Install with `pip install luxem`. You'll need `gcc` and `python3-dev` to compile the underlying C code.
Deserializes a document and returns an array of root values. Any typed values in the document will be converted to Typed.
Serializes a single root element with Writer. kwargs are passed to the constructor. In dumps the serialized data is returned. To serialize multiple root elements you may call this function multiple times or use the Writer class directly.
Serializes and deserializes ascii16 data. ascii16 is a binary encoding using only the letters abcdefghijklmnop.
This represents an explicitly typed value.
Creates a typed value with type attribute name and wrapped value attribute value.
Constructs a Reader and initializes its read callbacks. All callbacks must be provided.
object_begin, object_end, array_begin, and array_end take a callback in the format:
def callback(): return
key, type and primitive take a callback that accepts one string argument, in the format:
def callback(value): return
If any callback raises an exception, parsing stops and the exception is propagated up to the feed call.
data must either be bytes or a binary file.
Parses the byte-string provided as the first parameter and returns the number of characters from the string that were consumed. If parsing multiple chunks, any unconsumed characters of the byte-string must be provided again, at the beginning of the next fed string.
If finish is True, will conclude the last state encountered while parsing if possible. Set finish to true if no more data is available.
Reads and parses the entire file passed as the first argument. finish is ignored.
All arguments are optional.
If target is None all data will be written to an internal buffer. Retrieve the data with dump(). If target is a binary file, data will be written to the file and flushed when the Writer is destroyed. If target is a callback it will be invoked with generated chunks of bytes. Any exceptions raised in the callback will be propagated up. The callback has the format:
def callback(data): return
If pretty is True then whitespace will be added to the output based on use_spaces and the indent_multiple.
Returns written data as a byte string. Only valid when not serializing with a callback or file.
Writes any object, recursively serializing lists and dicts as arrays and objects. Any Typed value is written as a type. Returns self.
Opens an object. Returns self.
Ends an open object. Returns self.
Opens an array. Returns self.
Ends an open array. Returns self.
Writes an object key. Returns self. Only valid in an object.
Writes a type. Returns self. Only valid before a primitive, object begin, or array begin.
Writes a primitive. Returns self.
luxem © Rendaw, Zarbosoft 2017
luxem-python © Rendaw, Zarbosoft 2017