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.
pip install databindVerified import paths — ran on the pinned version, not inferred.
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`.
Update import statements: e.g., `from databind.json import dump` instead of `from databind.json import dump`.
Always specify type parameters for generic types, e.g., `field: list[YourType]`.
Upgrade to `databind` version 4.5.4 or newer to fix the `RecursionError` related to Union inheritance.
Create a dedicated subclass that binds the `TypeVar` to a concrete type or another bounded `TypeVar` (e.g., `@dataclass class MySpecificClass(MyClass['MySpecificClass']): pass`).
Explicitly define the type parameters for generic types. For example, change `list` to `list[YourType]` or `MyClass` to `MySpecificClass(MyClass['MySpecificClass'])`.
Upgrade to `databind` version 4.5.4 or newer. If upgrading is not immediately possible, consider simplifying `Union` definitions or inheritance structures.
Use the `databind.core.ExtraKeys` setting. Apply `@ExtraKeys()` to the dataclass, use `Annotated[FieldType, ExtraKeys()]` for a specific field, or pass `settings=[ExtraKeys()]` to the `load()` function.