pylits is a high-performance, deterministic serialization format for pure Python literals.
It provides extremely fast and reliable encoding/decoding while intentionally supporting only safe literal types, making it suitable for:
- Storing data in files (safely than eval())
- Transforming your DB into dynamic typed structures with support for lists and dictionaries
- Hashing
- ⚡ Very fast — minimal parsing overhead compared to JSON-like formats
- 🔒 Safe by design — supports only pure Python literals
- 🎯 Deterministic — identical data always produces identical encoded output
- 🧩 Zero dependencies — pure Python implementation
- 🔁 Lossless round-trip —
decode(encode(x)) == x
pylits works strictly with Python literal structures:
SupportedTypes = (
bool
| int
| float
| str
| list["SupportedTypes"]
| tuple["SupportedTypes", ...]
| set["SupportedTypes"]
| dict["SupportedTypes", "SupportedTypes"]
| None
)Anything outside this set is intentionally not supported.
pip install pylitsimport pylits
data = [1, "2", True, (None, {"Pylits": 21})]
encoded = pylits.encode(data)
decoded = pylits.decode(encoded)
assert decoded == datapylits.encode([1, "2"])
# "2l1i11s2"
pylits.decode("2l1i11s2")
# [1, "2"]pylits.encode(["A", "AB", "ABC", "ABCD"])
# "4l1sA2sAB3sABC4sABCD"pylits.encode([True, False])
# "2l1bT1bF"A modified internal encoder guarantees stable output even when:
- dictionary key order differs
- set element order differs
This makes pylits suitable for hashing.
MIT License
Copyright (c) 2026 Romashka
