Skip to main content
lodum: A high-performance Python serialization framework 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 pickle

Universal

One API for JSON, YAML, TOML, MsgPack, CBOR, BSON, and Pickle

Extensible

Native support for numpy, pandas, and polars without extra glue code

Validated

Built-in validators (Range, Length) and schema generation

WASM ready

Full Pyodide/WASM compatibility for browser and edge deployments

Core concepts

The architecture of lodum is built on a clear separation of concerns, just like serde:
  1. 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.
  2. Data formats (loaders/dumpers) - The logic for converting data into a specific format (like JSON) is handled by Loader and Dumper implementations. This makes the core library format-agnostic.
This means you can define how your data is structured once, and then easily encode it to multiple formats (JSON, YAML, etc.) by simply using a different module.

Quick example

Here’s a taste of what lodum can do:
from lodum import lodum, json
from dataclasses import dataclass

@lodum
@dataclass
class User:
    name: str
    age: int
    is_active: bool

user = User(name="Alex", age=30, is_active=True)

# Encode to JSON
json_string = json.dumps(user)
print(json_string)
# {"name": "Alex", "age": 30, "is_active": true}

# Decode from JSON
json_data = '{"name": "Barbara", "age": 25, "is_active": false}'
barbara = json.loads(User, json_data)
print(f"Name: {barbara.name}, Age: {barbara.age}")
# Name: Barbara, Age: 25

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

Build docs developers (and LLMs) love