Skip to main content

Convert dicts into dataclasses. Supports lists, dicts and unions.

Project description

Dict 2 Dataclass

This is a simple python script that converts a dictionary to a class. It is useful when you want to access the dictionary values as class attributes.

Usage

from dict2dataclass import FromDict
from dataclasses import dataclass

@dataclass
class Address(FromDict):
    street: str
    city: str
    state: str

@dataclass
class Person(FromDict):
    name: str
    age: int
    address: Address

data = {
    "name": "John Doe",
    "age": 30,
    "address": {
        "street": "123 Main St",
        "city": "Springfield",
        "state": "IL"
    }
}

person = Person.from_dict(data)
print(person.name) # John Doe

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

dict2dataclass-0.1.0.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

dict2dataclass-0.1.0-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file dict2dataclass-0.1.0.tar.gz.

File metadata

  • Download URL: dict2dataclass-0.1.0.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.2 Darwin/23.5.0

File hashes

Hashes for dict2dataclass-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a98367b22222d5574116d2ea07e967ba42728afcf452a3db46b3d6fe66610530
MD5 1015379b1d2e87473ba2eba03185e190
BLAKE2b-256 b8dd3069f313e44cffe5dfec6ab1e0130dfd690d18269fda689260b0ddc0c9c4

See more details on using hashes here.

File details

Details for the file dict2dataclass-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: dict2dataclass-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.2 Darwin/23.5.0

File hashes

Hashes for dict2dataclass-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d70dc6965382cba3efcc2a7c7a77fc52c32ecbfe4d97c5c09ff6b28d976abeac
MD5 89d6d441762c85e06f9749606a39c1f9
BLAKE2b-256 d5fc1ec606648a98763582e19a39c4ea14d608e615d4f3b0951edc2c05cd4791

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