Skip to main content

Parser and serializer for Sled, a serialization language for developer-friendly reading and writing

Project description

parsled

Python package for parsing Sled and serializing Python objects as Sled.

Sled is a serialization language for developer-friendly reading and writing.

Parse: Sled to Python dict

To parse Sled into a Python dict, call from_sled().

from parsled import from_sled

with open("path/to/my_file.sled", mode="r") as f:
    data = from_sled(f.read())

Serialize: Python to Sled

This package provides 2 ways to serialize Python objects.

  1. Call to_sled().
  2. Instantiate a SledSerializer and call its to_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.

from parsled import SledSerializer, to_sled

data = {}
other_data = {}

# Approach #1
sled = to_sled(data)

# Approach #2
sled_serializer = SledSerializer()
sled = sled_serializer.to_sled(data)
other_sled = sled_serializer.to_sled(other_data)

Default serialization

Instances of the following Python data types (on the left) will be serialized as the associated Sled data type (on the right).

  • None: nil
  • bool: boolean
  • bytes: hex
  • int: integer
  • float: float
  • str: identity, quote, or concat
  • Mapping[str, Entity]: smap
  • Mapping[int, Entity]: imap
  • Iterable that is not a Mapping: list
  • dataclass: smap

For an object to be serialized as a standalone Sled document, it should be a Mapping[str, Entity] or dataclass instance, since the top level of a Sled document is always a smap.

A dataclass instance is implicitly converted into a Mapping by calling dataclasses.fields() (unless the original instance is itself also a Mapping, in which case that takes precedence).

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

parsled-0.2.0.tar.gz (24.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

parsled-0.2.0-py3-none-any.whl (30.0 kB view details)

Uploaded Python 3

File details

Details for the file parsled-0.2.0.tar.gz.

File metadata

  • Download URL: parsled-0.2.0.tar.gz
  • Upload date:
  • Size: 24.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for parsled-0.2.0.tar.gz
Algorithm Hash digest
SHA256 0d5b3720f6a424f7cad2ab6320c8ed67e822b2c17e009c5e529a17fd30894e7a
MD5 b9394f2564b55cf657565e125c3f39aa
BLAKE2b-256 645559065febd1f3c2292f33b0acff5d8bce88ba6b79a8abb8d1d0802bbe9c50

See more details on using hashes here.

File details

Details for the file parsled-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: parsled-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 30.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for parsled-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cbf329e4a62430b97fb784e5f128fa57ace9f2dec39f06914dda2129bff73227
MD5 a98c193387e6203c9c2a03b62a9c2659
BLAKE2b-256 f8476157d1a873aa95b845fb517bf9deb157faf53d02a1cfbf1ecf33f1c29b2d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page