Databind

4.5.4 · active · verified Thu Apr 16

Databind is a Python library, currently at version 4.5.4, designed for de-serializing and serializing Python dataclasses. Inspired by `jackson-databind`, it provides a flexible framework that understands most native Python types and dataclasses, primarily for configuration loading rather than high-performance use cases. It maintains a regular release cadence with recent updates fixing various serialization issues.

Common errors

Warnings

Install

Imports

Quickstart

This example demonstrates basic serialization and deserialization of Python dataclasses to/from a dictionary (JSON-like structure) using `databind.json.dump` and `databind.json.load`.

from dataclasses import dataclass
from databind.json import dump, load

@dataclass
class Server:
    host: str
    port: int

@dataclass
class Config:
    server: Server

dict_payload = {"server": {"host": "localhost", "port": 8080}}

# Deserialize
loaded_config = load(dict_payload, Config)
print(f"Loaded Config: {loaded_config}")
assert loaded_config == Config(server=Server(host="localhost", port=8080))

# Serialize
dumped_payload = dump(loaded_config, Config)
print(f"Dumped Payload: {dumped_payload}")
assert dumped_payload == dict_payload

view raw JSON →