
lodum is a high-performance framework for loading and dumping Python data structures efficiently and ergonomically.
Think of it as
serde for Python.Why lodum?
Fast
~64% faster dumps than standard introspection using AST bytecode generation
Safe
Secure-by-default design. Blocks arbitrary code execution in
pickleUniversal
One API for JSON, YAML, TOML, MsgPack, CBOR, BSON, and Pickle
Extensible
Native support for
numpy, pandas, and polars without extra glue codeValidated
Built-in validators (
Range, Length) and schema generationWASM ready
Full Pyodide/WASM compatibility for browser and edge deployments
Core concepts
The architecture oflodum is built on a clear separation of concerns, just like serde:
-
Lodum-enabled data structures - You define the data you want to encode by decorating your classes with
@lodum. This decorator introspects your class to understand its structure. -
Data formats (loaders/dumpers) - The logic for converting data into a specific format (like JSON) is handled by
LoaderandDumperimplementations. This makes the core library format-agnostic.
Quick example
Here’s a taste of whatlodum can do:
Get started
Installation
Install lodum with pip or your favorite package manager
Quick start
Get up and running with lodum in minutes
Performance
lodum is designed for high performance. When you first use a @lodum-enabled class, the library analyzes its structure and generates specialized Python bytecode for serialization and deserialization using an internal Abstract Syntax Tree (AST) compiler.
This approach eliminates the overhead of generic introspection and getattr calls during runtime, resulting in:
- ~64% faster dumping (serialization) than the baseline
- ~35% faster loading (deserialization) than the baseline
Supported formats
lodum is designed to be format-agnostic, and new formats can be added by implementing the Dumper and Loader protocols:
- JSON -
lodum.json - YAML -
lodum.yaml - TOML -
lodum.toml - MessagePack -
lodum.msgpack - CBOR -
lodum.cbor - BSON -
lodum.bson - Pickle -
lodum.pickle(with SafeUnpickler)
Supported types
lodum supports a comprehensive set of Python types:
- Primitives -
int,str,float,bool,None - Collections -
list,dict,tuple,set,bytes,bytearray,array.array - Standard library -
datetime,enum.Enum,uuid.UUID,decimal.Decimal,pathlib.Path - Typing -
Optional,Union,Any,TypeVar - Third-party libraries -
numpy.ndarray,pandas.DataFrame,polars.DataFrame - Custom objects - Any class decorated with
@lodum
Next steps
Installation
Install lodum and get started
Quick start
Learn the basics in 5 minutes
API reference
Explore the complete API