Recursively cast json to python dataclasses, typing, and class. Also provides reverse.
Project description
Smart Cast
Recursively cast json to python dataclasses, typing, and class
Features
Supports
List[TV]Dict[TK, TV]Optional[TV]Uniondictlistdataclassintstrfloatbooleandatetime
useage
from smartcast import normal, cast
from typing import List, Optional, Union
import json
from dataclasses import dataclass
from enum import Enum, auto
class Option(Enum):
A = auto()
B = auto()
@dataclass
class Config:
value: Option
def test_simple():
value = Config(Option.A)
nobj = normal(value)
jstr = json.dumps(nobj)
jobj = json.loads(jstr)
revalue = cast(jobj, Config)
assert value == revalue
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
smartcast-0.2.0.tar.gz
(4.0 kB
view details)
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 smartcast-0.2.0.tar.gz.
File metadata
- Download URL: smartcast-0.2.0.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ee6e0fc2d22f634bf5eb8e6fbbfd730d38212ca11bc5c02a9573347f9520fef1
|
|
| MD5 |
9670f5750577570b825ffa585704b106
|
|
| BLAKE2b-256 |
a8a4f1b8932e0043d459b37f1c36bbbbc7b1e69caf8f9700eeef69f4c8ed02ce
|
File details
Details for the file smartcast-0.2.0-py3-none-any.whl.
File metadata
- Download URL: smartcast-0.2.0-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.2 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dcb80146588531478081efe2ef0538a3af251722918e090294d1b2a7e0826c97
|
|
| MD5 |
9df132d4fcc6781b52231ead845ee8f3
|
|
| BLAKE2b-256 |
45f6595cea52257a8995667b28652f7822214707328b65efdef4187ed512a378
|