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 description
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.core
anddatabind.json
packages 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
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file databind-4.5.2.tar.gz
.
File metadata
- Download URL: databind-4.5.2.tar.gz
- Upload date:
- Size: 43.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0a8aa0ff130a0306581c559388f5ef65e0fae7ef4b86412eacb1f4a0420006c4 |
|
MD5 | 9850327a73c2d3aa7988ab5d2666386e |
|
BLAKE2b-256 | 0cb8a6beffa3dd3d7898003d32b3ff5dc0be422c54efed5e0e3f85e92c65c2b2 |
File details
Details for the file databind-4.5.2-py3-none-any.whl
.
File metadata
- Download URL: databind-4.5.2-py3-none-any.whl
- Upload date:
- Size: 49.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.10.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b9c3a03c0414aa4567f095d7218ac904bd2b267b58e3763dac28e83d64b69770 |
|
MD5 | 48d9fab98e1e3f250bd7113f862fe904 |
|
BLAKE2b-256 | 0b5b39577d7629da11765786f45a37dccdf7f420038f6040325fe1ca40f52a93 |