De-/serialize Python dataclasses to or from JSON payloads. Compatible with Python 3.7 and newer.
Reason this release was yanked:
Some weird issue with this release..
Project description
databind.json
The databind.json
package implements the de-/serialization to or from JSON payloads using
the databind.core
framework.
Quickstart
import databind.json
import dataclasses
@dataclasses.dataclass
class ServerConfig:
host: str
port: int = 8080
@dataclasses.dataclass
class MainConfig:
server: ServerConfig
payload = { 'server': { 'host': '127.0.0.1' } }
config = databind.json.load(payload, MainConfig)
assert config == MainConfig(ServerConfig('127.0.0.1'))
Examples for common use cases
Unions with literal matches
import dataclasses
import databind.json
from typing import Literal
@dataclasses.dataclass
class AwsMachine:
region: str
name: str
instance_id: str
provider: Literal["aws"] = "aws"
@dataclasses.dataclass
class AzureMachine:
resource_group: str
name: str
provider: Literal["azure"] = "azure"
Machine = AwsMachine | AzureMachine
payload = {"provider": "azure", "resource_group": "foo", "name": "bar"}
assert databind.json.load(payload) == AzureMachine("foo", "bar")
Copyright © 2020 – 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
databind.json-2.0.8.tar.gz
(11.1 kB
view hashes)
Built Distributions
Close
Hashes for databind_json-2.0.8-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c70b08d85c0944b52498a100eea4645d2bc7c0e7ae0a439d5c6dad22edd0dd77 |
|
MD5 | 534bcc4e7c21f2e9bb7639c0fafdfc14 |
|
BLAKE2b-256 | 8e3490290d87cd03827fba97c01b3216fe6046ec9da49615f53ccd83e0fc2c92 |
Close
Hashes for databind.json-2.0.8-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | efbe096775874145c870c04201f549c16fac41f092d122da228247db4809ad3f |
|
MD5 | 0e71cad49e1880be06e81fd0a43b31ef |
|
BLAKE2b-256 | c8d072e6a3286aea9ec6e5133f85e4fc3665f41565f783e61268cdd3f45be572 |