Parsled#
Python package for parsing Sled and serializing Python objects as Sled.
Sled is a serialization language for developer-friendly reading and writing.
Setup#
parsled is available on PyPI.
You can install it using your preferred Python package manager.
For example:
Parse: Sled to Python dict#
To parse a str of Sled into a Python dict, call from_sled().
Python
sled_text = '''
name = "John Doe"
age = 50
children = [Jack ; Jill]
'''
data = parsled.from_sled(sled_text)
assert data == {
"name": "John Doe",
"age": 50,
"children": ["Jack", "Jill"],
}
To parse a Sled file, read it to a str, then pass that into from_sled().
Python
with open("path/to/my_file.sled", mode="r") as f:
sled_text = f.read()
data = parsled.from_sled(sled_text)
Serialize: Python object to Sled#
We have 2 main ways to serialize Python objects.
- Call
to_sled(). - Instantiate a
SledSerializerand call itsto_sled()method.
Both have the same configuration options and defaults.
For details, refer to the SledSerializer documentation.
Approach #1 simply does approach #2 under the hood. Approach #2 may be useful if you want to set a configuration once and reuse that for serialization multiple times.