Skip to main content

Map a dict to a dataclass and log differences

Project description

Dataclass Map And Logtag Build codecov

Map dictionaries to pydantic dataclasses, log any extra attributes.

Example

from dataclass_map_and_log.mapper import DataclassMapper

@dataclass
class Child:
    name: str
    surname: str


@dataclass
class SingleChild:
    name: str


@dataclass
class Parent:
    name: str
    surname: str
    children: List[Child]
    single_child: SingleChild
    
data = {
    "name": "parent_name",
    "surname": "parent_surname",
    "extra": "parent_extra_data",
    "children": [
        {
            "name": "child1_name",
            "surname": "child1_surname",
            "extra": "child_extra_data",
        },
        {
            "name": "child2_name",
            "surname": "child2_surname",
        },
    ],
    "single_child": {"name": "test"},
}

definition = DataclassMapper.map(Parent, data)

You can then access the dataclass instance like:

definition.single_child.name

And you would have gotten the following warning log messages:

"Unexpected attribute extra on class <class 'tests.test_dataclass_map_and_log.Parent'> with value parent_extra_data",
"Unexpected attribute extra on class <class 'tests.test_dataclass_map_and_log.Child'> with value child_extra_data",

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

dataclass_map_and_log-0.1.6.tar.gz (14.2 kB view details)

Uploaded Source

Built Distribution

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

dataclass_map_and_log-0.1.6-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

Details for the file dataclass_map_and_log-0.1.6.tar.gz.

File metadata

  • Download URL: dataclass_map_and_log-0.1.6.tar.gz
  • Upload date:
  • Size: 14.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for dataclass_map_and_log-0.1.6.tar.gz
Algorithm Hash digest
SHA256 e3c005b1d27093d24a65d9bf01b28b1dc4f7c968b90b2391027f388020687dff
MD5 95741a038a3f73c8cb08a9d1cba8c8d2
BLAKE2b-256 07382d2a09a77afffb3b165dd7a74ed918785d4557f7cfb4d0d717325788f26e

See more details on using hashes here.

File details

Details for the file dataclass_map_and_log-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: dataclass_map_and_log-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 15.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for dataclass_map_and_log-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 0c913ffee578333524dc3c819166a5283166413d9543c774bb71a87d288c44a3
MD5 ac0667774cb90035a1e95a43d98f27a5
BLAKE2b-256 3b4147d4ee8551fc4c5d905226d3bac0bde515228d15e4459b4565cb6a2f16d7

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