Skip to main content

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

Python versions

Databind is a Python serialization library on top of dataclasses, inspired by similar libraries from other languages like jackson-databind and serde-rs.

CORE Guide | JSON Examples

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

Copyright © 2022 – Niklas Rosenstein

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

databind-4.3.0.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

databind-4.3.0-py3-none-any.whl (2.6 kB view details)

Uploaded Python 3

File details

Details for the file databind-4.3.0.tar.gz.

File metadata

  • Download URL: databind-4.3.0.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.3 readme-renderer/37.3 requests/2.28.1 requests-toolbelt/0.10.1 urllib3/1.26.12 tqdm/4.64.1 importlib-metadata/5.0.0 keyring/23.11.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.11

File hashes

Hashes for databind-4.3.0.tar.gz
Algorithm Hash digest
SHA256 d3b12a5fd22c03bcc75508a886cc3a3ee19c84529cc68f7e7f6dc217495afb1e
MD5 ab5c807de4b4b1255550e9b051d94167
BLAKE2b-256 16a5670c4b88df52da6c313c1b359e8551224b97b85e5a3d403cd2e9e73f09bb

See more details on using hashes here.

File details

Details for the file databind-4.3.0-py3-none-any.whl.

File metadata

  • Download URL: databind-4.3.0-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.8.3 readme-renderer/37.3 requests/2.28.1 requests-toolbelt/0.10.1 urllib3/1.26.12 tqdm/4.64.1 importlib-metadata/5.0.0 keyring/23.11.0 rfc3986/2.0.0 colorama/0.4.6 CPython/3.10.11

File hashes

Hashes for databind-4.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b28a75aaee8533014913c18abb769d7311adceb8446da881b58639eac8e5155b
MD5 d86a80a4dbe504fdb1b810d692425cd2
BLAKE2b-256 0a22065057646448df25588cde21f2406d4943c7cfa5a45588da10fa7a4e4fe1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page