Databind is a library inspired by jackson-databind to de-/serialize Python dataclasses. The `databind` package will install the full suite of databind packages. Compatible with Python 3.8 and newer.
Maintained. Last release 6 months ago, commits in 1 of the last 26 weeks. Weaker on commit activity and contributor spread.
pip install databind
databind
The databind package provides a (de)serialization framework that understands most native Python types as well as
dataclasses, as well as an implementation for serialize to/from JSON-like nested data structures.
Databind is intended mostly for flexible and easy to use configuration loading. It does not try achieve high-performance; you should look towards e.g. mashumaro for this usecase.
Example
@dataclass
class Server:
host: str
port: int
@dataclass
class Config:
server: Server
from databind.json import dump, load
dict_payload = {"server": {"host": "localhost", "port": 8080}}
loaded = Config(server=Server(host="localhost", port=8080))
assert load(dict_payload, Config) == loaded
assert dump(loaded, Config) == dict_payload
Features ✨
- Support for a plethora of builtin types, including
Enum,Decimal,UUID,Path,datetime,date,time,timedelta - Support for multiple union serialization modes (nested, flat, keyed,
typing.Literal) - Support for generic types, e.g.
load([{"name": "Jane Doe"}], list[Person]) - Support for new-style type hints in older Python versions when using forward refererences (strings or
__future__.annotations) thanks to typeapi - Support for customized serialization and deserialization of types