Databind Core

4.5.4 · deprecated · verified Thu Apr 16

Databind Core is a Python library, currently at version 4.5.4, designed for de-serializing Python dataclasses, drawing inspiration from Java's Jackson Databind. It is compatible with Python 3.8 and newer. This package is now deprecated; users are advised to migrate to the `databind` package, which consolidates `databind-core` and `databind-json`.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates basic JSON de/serialization using the `databind` package, which is the recommended successor to `databind-core`. It shows how to define dataclasses and use `load` and `dump` for conversion between dictionaries and dataclass instances.

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

# Note: This quickstart uses the 'databind' package (the recommended successor)
# as 'databind-core' is deprecated and its JSON functionality has moved.

@dataclass
class Server:
    host: str
    port: int

@dataclass
class Config:
    server: Server

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

# Load data into a dataclass instance
loaded_config = load(dict_payload, Config)
print(f"Loaded Config: {loaded_config}")

# Dump a dataclass instance back to a dictionary
dumped_payload = dump(loaded_config, Config)
print(f"Dumped Payload: {dumped_payload}")

assert loaded_config == Config(server=Server(host="localhost", port=8080))
assert dumped_payload == dict_payload

view raw JSON →