databind

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.

65 个版本 Python >=3.8
Niklas Rosenstein <Niklas Rosenstein <rosensteinniklas@gmail.com>>
安装
pip install databind
poetry add databind
pipenv install databind
conda install databind
描述

databind

Python versions Documentation

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 (or typing_extensions.Annotated): full_name: Annotated[str, Alias("fullName")] or FullNameField = Annotated[str, Alias("fullName")]

Notable release notes

4.5.0

  • Merged databind.core and databind.json packages into databind. 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.5 2026-05-22
4.5.4 2026-04-02
4.5.3 2026-03-26
4.5.2 2024-05-31
4.5.1 2024-04-02
4.5.0 2024-03-19
4.4.2 2023-11-11
4.4.1 2023-08-17
4.4.0 2023-06-21
4.3.2 2023-06-09
4.3.1 2023-06-09
4.3.0 2023-05-28
4.2.8 2023-05-28
4.2.7 2023-05-28
4.2.6 2023-05-28
4.2.5 2023-04-29
4.2.4 2023-04-12
4.2.3 2023-04-12
4.2.2 2022-11-30
4.2.1 2022-11-21
4.2.0 2022-11-21
4.1.1 2022-11-11
4.1.0 2022-11-10
4.0.0 2022-11-06
3.0.0 2022-11-05
2.0.9 2022-11-03
2.0.8 2022-09-27
2.0.7 2022-06-20
2.0.6 2022-06-20
2.0.5 2022-06-16
2.0.3 2022-05-11
2.0.2 2022-05-11
2.0.1 2022-05-09
2.0.0 2022-03-31
2.0.0a4 2022-03-29
2.0.0a3 2022-03-29
2.0.0a2 2022-03-24
2.0.0a1 2022-03-23
1.5.3 2022-07-04
1.5.2 2022-03-23
1.5.1 2022-02-26
1.5.0 2022-02-25
1.4.0 2022-01-22
1.3.2 2022-01-10
1.3.1 2022-01-08
1.3.0 2022-01-06
1.2.6 2021-12-29
1.2.4 2021-10-23
1.2.3 2021-09-06
1.2.2 2021-09-01
1.2.1 2021-08-30
1.2.0 2021-08-20
1.1.6 2021-08-18
1.1.5 2021-08-16
1.1.4 2021-08-10
1.1.3 2021-08-10
1.1.2 2021-08-06
1.1.1 2021-08-03
1.1.0 2021-08-03
1.0.1 2021-07-22
1.0.0 2021-07-21
0.3.1 2020-11-27
0.3.0 2020-11-20
0.2.0 2020-08-14
0.1.0 2020-08-01