Metadata-Version: 2.4
Name: parsled
Version: 0.2.1
Summary: Parser and serializer for Sled, a serialization language for developer-friendly reading and writing
Keywords: sled,parse,serialize,deserialize,readable,language,format
Author: Kawin
Author-email: Kawin <kawin.open@gmail.com>
License-Expression: MIT
License-File: LICENSE
Classifier: Intended Audience :: Developers
Classifier: Topic :: File Formats
Classifier: Typing :: Typed
Maintainer: Kawin
Maintainer-email: Kawin <kawin.open@gmail.com>
Requires-Python: >=3.8
Project-URL: Homepage, https://parsled.readthedocs.io
Project-URL: Documentation, https://parsled.readthedocs.io
Project-URL: Source, https://github.com/kawindex/sled/tree/main/python
Project-URL: Issues, https://github.com/kawindex/sled/issues
Description-Content-Type: text/markdown

# 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:
```sh
pip install parsled
```


## Parse: Sled to Python `dict`

To parse a `str` of Sled into a Python `dict`, call [`from_sled()`](https://parsled.readthedocs.io/en/stable/api/#parsled._parser.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()`](https://parsled.readthedocs.io/en/stable/api/#parsled._parser.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.

1. Call [`to_sled()`](https://parsled.readthedocs.io/en/stable/api/#parsled.to_sled).
2. Instantiate a [`SledSerializer`](https://parsled.readthedocs.io/en/stable/api/#parsled.SledSerializer) and call its [`to_sled()`](https://parsled.readthedocs.io/en/stable/api/#parsled.SledSerializer.to_sled) method.

Both have the same configuration options and defaults.
For details, refer to the [`SledSerializer` documentation](https://parsled.readthedocs.io/en/stable/api/#parsled.SledSerializer).

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.

```python
data = {}
other_data = {}

# Approach #1
sled_output = parsled.to_sled(data)

# Approach #2
sled_serializer = parsled.SledSerializer()
sled_output = sled_serializer.to_sled(data)
other_sled_output = sled_serializer.to_sled(other_data)
```
