Skip to main content

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]
  • Union
  • dict
  • list
  • dataclass
  • int
  • str
  • float
  • boolean
  • datetime

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


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)

Uploaded Source

Built Distribution

smartcast-0.2.0-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

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

Hashes for smartcast-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ee6e0fc2d22f634bf5eb8e6fbbfd730d38212ca11bc5c02a9573347f9520fef1
MD5 9670f5750577570b825ffa585704b106
BLAKE2b-256 a8a4f1b8932e0043d459b37f1c36bbbbc7b1e69caf8f9700eeef69f4c8ed02ce

See more details on using hashes here.

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

Hashes for smartcast-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dcb80146588531478081efe2ef0538a3af251722918e090294d1b2a7e0826c97
MD5 9df132d4fcc6781b52231ead845ee8f3
BLAKE2b-256 45f6595cea52257a8995667b28652f7822214707328b65efdef4187ed512a378

See more details on using hashes here.

Supported by

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