{"id":7136,"library":"databind","title":"Databind","description":"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.","status":"active","version":"4.5.4","language":"en","source_language":"en","source_url":"https://github.com/NiklasRosenstein/python-databind","tags":["serialization","deserialization","dataclasses","json","type-hints"],"install":[{"cmd":"pip install databind","lang":"bash","label":"Install latest version"}],"dependencies":[{"reason":"Compatible with Python 3.8 and newer versions.","package":"Python","optional":false}],"imports":[{"note":"As of v4.5.0, `databind.core` and `databind.json` modules were merged into the top-level `databind` package.","wrong":"from databind.core import dump","symbol":"dump","correct":"from databind.json import dump"},{"note":"As of v4.5.0, `databind.core` and `databind.json` modules were merged into the top-level `databind` package.","wrong":"from databind.core import load","symbol":"load","correct":"from databind.json import load"}],"quickstart":{"code":"from dataclasses import dataclass\nfrom databind.json import dump, load\n\n@dataclass\nclass Server:\n    host: str\n    port: int\n\n@dataclass\nclass Config:\n    server: Server\n\ndict_payload = {\"server\": {\"host\": \"localhost\", \"port\": 8080}}\n\n# Deserialize\nloaded_config = load(dict_payload, Config)\nprint(f\"Loaded Config: {loaded_config}\")\nassert loaded_config == Config(server=Server(host=\"localhost\", port=8080))\n\n# Serialize\ndumped_payload = dump(loaded_config, Config)\nprint(f\"Dumped Payload: {dumped_payload}\")\nassert dumped_payload == dict_payload","lang":"python","description":"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`."},"warnings":[{"fix":"Update import statements: e.g., `from databind.json import dump` instead of `from databind.json import dump`.","message":"The `databind.core` and `databind.json` packages were merged directly into the top-level `databind` package in version 4.5.0. Imports should be updated from `databind.core.foo` or `databind.json.bar` to `databind.foo` or `databind.bar` respectively. This version also dropped support for Python 3.6 and 3.7.","severity":"breaking","affected_versions":">=4.5.0"},{"fix":"Always specify type parameters for generic types, e.g., `field: list[YourType]`.","message":"Databind does not assume `Any` for missing type parameters in generics. If a generic type (e.g., `list`) is used without a specific type hint (e.g., `list[str]`), a `NoMatchingConverter` error will be raised during deserialization.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Upgrade to `databind` version 4.5.4 or newer to fix the `RecursionError` related to Union inheritance.","message":"Beware of inherited Union settings via Method Resolution Order (MRO), which historically led to `RecursionError` during serialization/deserialization. This was a known issue with complex inheritance hierarchies involving `Union` types.","severity":"gotcha","affected_versions":"<4.5.4"},{"fix":"Create a dedicated subclass that binds the `TypeVar` to a concrete type or another bounded `TypeVar` (e.g., `@dataclass class MySpecificClass(MyClass['MySpecificClass']): pass`).","message":"Fields from generic dataclasses with unspecified `TypeVar`s might not be serialized correctly. For instance, a generic dataclass `MyClass(Generic[T])` where `T` is not bound in a subclass can lead to `no deserializer for TypeHint(~T)`.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Explicitly define the type parameters for generic types. For example, change `list` to `list[YourType]` or `MyClass` to `MySpecificClass(MyClass['MySpecificClass'])`.","cause":"A generic type (e.g., `list` or a custom generic dataclass) was used in a type hint without specifying its type parameters (e.g., `list[str]`), causing databind to not know how to deserialize the inner type.","error":"databind.core.converter.NoMatchingConverter: no deserializer for `TypeHint(~T_Page)` and payload of type `dict`"},{"fix":"Upgrade to `databind` version 4.5.4 or newer. If upgrading is not immediately possible, consider simplifying `Union` definitions or inheritance structures.","cause":"In versions prior to 4.5.4, complex inheritance chains combined with `Union` types could lead to infinite recursion during converter lookup due to an issue with MRO and Union settings.","error":"RecursionError: maximum recursion depth exceeded"},{"fix":"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.","cause":"The input payload contains keys that are not defined as fields in the target dataclass, and the `ExtraKeys` setting is not enabled to allow or record these additional fields.","error":"databind.core.converter.ConversionError: Unknown field 'extra_key'"}]}