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.7 and newer.
Project description
databind
Databind is a Python serialization library on top of dataclasses, inspired by similar libraries from other languages like jackson-databind and serde-rs.
Overview 📖
The databind.core package provides the core framework for databind. It is then used by databind.json to provide
comprehensive serializatio support between Python and JSON-like data structure. The serialization can easily be
extended to YAML or TOML by combining it with respective libraries (e.g. pyaaml and tomli).
@dataclass
class Server:
host: str
port: int
@dataclass
class Config:
server: Server
from databind.json import dump, load
assert load({"server": {"host": "localhost", "port": 8080}}, Config) == Config(server=Server(host='localhost', port=8080))
assert dump(Config(server=Server(host='localhost', port=8080)), Config) == {"server": {"host": "localhost", "port": 8080}}
If you install the databind proxy package, you get matching versions of databind.core and databind.json.
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
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file databind-4.4.2.tar.gz.
File metadata
- Download URL: databind-4.4.2.tar.gz
- Upload date:
- Size: 2.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/37.3 requests/2.28.2 requests-toolbelt/0.10.1 urllib3/1.26.14 tqdm/4.64.1 importlib-metadata/6.0.0 keyring/23.13.1 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b1ef7e0d8b5fb1134b432de6ea9de3c4fa9ea96c0a81cda9708759acc1292404
|
|
| MD5 |
07ae72182dda9d34b368b102678eafe8
|
|
| BLAKE2b-256 |
ea3a6293edd1c3581f8aebe4bc54855746ca9c590f7ba6e7070bd8f6cd8928c1
|
File details
Details for the file databind-4.4.2-py3-none-any.whl.
File metadata
- Download URL: databind-4.4.2-py3-none-any.whl
- Upload date:
- Size: 2.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.8.0 pkginfo/1.9.6 readme-renderer/37.3 requests/2.28.2 requests-toolbelt/0.10.1 urllib3/1.26.14 tqdm/4.64.1 importlib-metadata/6.0.0 keyring/23.13.1 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d002d9e79fd005f9261d46e1407c9f7ff7bb093ecabd97e465223852cab4d015
|
|
| MD5 |
a5e2aaaec1d94352f9c77ceaec46921e
|
|
| BLAKE2b-256 |
63a15d912d504d8058215c40407ab60afab4bcccee5cb9cfced0c3fbf7a414b5
|