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.
Project Links
Meta
Author: Niklas Rosenstein
Requires Python: >=3.8.0,<4.0.0
Classifiers
License
- OSI Approved :: MIT License
Programming Language
- Python :: 3
- Python :: 3.8
- Python :: 3.9
- Python :: 3.10
- Python :: 3.11
- Python :: 3.12

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
- Support for flattening fields of a nested dataclass or collecting remaining fields in a
dict - Full runtime type checking during serialization
- Use "settings" to customize serialization behaviour
- As global settings per
load()/dump()call:load(..., settings=[ExtraKeys(True)]) - As class-level settings using a decorator:
@Union(style=Union.FLAT)or@ExtraKeys(True) - As type-hint level settings using
typing.Annotated(ortyping_extensions.Annotated):full_name: Annotated[str, Alias("fullName")]orFullNameField = Annotated[str, Alias("fullName")]
- As global settings per
Notable release notes
4.5.0
- Merged
databind.coreanddatabind.jsonpackages intodatabind. The old PyPI packages will remain as proxies until the next minor version. - Dropped support for Python 3.6 and 3.7.
Copyright © 2022 – Niklas Rosenstein
4.5.2
May 31, 2024
4.5.1
Apr 02, 2024
4.5.0
Mar 19, 2024
4.4.2
Nov 11, 2023
4.4.1
Aug 17, 2023
4.4.0
Jun 21, 2023
4.3.2
Jun 09, 2023
4.3.1
Jun 09, 2023
4.3.0
May 28, 2023
4.2.8
May 28, 2023
4.2.7
May 28, 2023
4.2.6
May 28, 2023
4.2.5
Apr 29, 2023
4.2.4
Apr 12, 2023
4.2.3
Apr 12, 2023
4.2.2
Nov 30, 2022
4.2.1
Nov 21, 2022
4.2.0
Nov 21, 2022
4.1.1
Nov 11, 2022
4.1.0
Nov 10, 2022
4.0.0
Nov 06, 2022
3.0.0
Nov 05, 2022
2.0.9
Nov 03, 2022
2.0.8
Sep 27, 2022
2.0.7
Jun 20, 2022
2.0.6
Jun 20, 2022
2.0.5
Jun 16, 2022
2.0.3
May 11, 2022
2.0.2
May 11, 2022
2.0.1
May 09, 2022
2.0.0
Mar 31, 2022
2.0.0a4
Mar 29, 2022
2.0.0a3
Mar 29, 2022
2.0.0a2
Mar 24, 2022
2.0.0a1
Mar 23, 2022
1.5.3
Jul 04, 2022
1.5.2
Mar 23, 2022
1.5.1
Feb 26, 2022
1.5.0
Feb 25, 2022
1.4.0
Jan 22, 2022
1.3.2
Jan 10, 2022
1.3.1
Jan 08, 2022
1.3.0
Jan 06, 2022
1.2.6
Dec 29, 2021
1.2.4
Oct 23, 2021
1.2.3
Sep 06, 2021
1.2.2
Sep 01, 2021
1.2.1
Aug 30, 2021
1.2.0
Aug 20, 2021
1.1.6
Aug 18, 2021
1.1.5
Aug 16, 2021
1.1.4
Aug 10, 2021
1.1.3
Aug 10, 2021
1.1.2
Aug 06, 2021
1.1.1
Aug 03, 2021
1.1.0
Aug 03, 2021
1.0.1
Jul 22, 2021
1.0.0
Jul 21, 2021
0.3.1
Nov 27, 2020
0.3.0
Nov 20, 2020
0.2.0
Aug 14, 2020
0.1.0
Aug 01, 2020