Skip to main content

Using this package you can do a deep conversion of your dataclass to a dictionary and initialize it from dict.

Getting it

To download deeply, either fork this github repo or simply use PyPI via pip.

$ pip install deeply

Usage

1 - Import

from deeply import Deeply
from dataclasses import dataclass

2 - Define your data classes with the following inheritance:

@dataclass
class A(Deeply):
    a1: int
    a2: int


@dataclass
class B(Deeply):
    b1: str
    b2: str

@dataclass
class C(Deeply):
    a: A
    b: B

3 - Create an instance of the class and you can already use it:

c = C(A(1, 2), B('foo', 'bar'))

c.to_web()
# {'a': {'a1': 1, 'a2': 2}, 'b': {'b1': 'foo', 'b2': 'bar'}}

4 - You can also initialize your class from a dictionary:

c = C.init_from_dict({
    'a': {
        'a1': 1,
        'a2': 2
    },
    'b': {
        'b1': 'foo',
        'b2': 'bar'
    }
})

# C(a=A(a1=1, a2=2), b=B(b1='foo', b2='bar'))

5 - And finally: you can set your own conversion rules in deep dict.

Deeply.rules: List[Tuple[Callable[[T], bool], Callable[[T], Any]]] = [
        (lambda obj: hasattr(obj, 'isoformat'), lambda obj: obj.isoformat()),
    ]

Metadata

Release files for deeply 1.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for deeply 1.0.3
File Size Uploaded Provenance Actions
deeply-1.0.3.tar.gz 2.4 kB Without provenance Details for deeply-1.0.3.tar.gz

Release files / deeply-1.0.3.tar.gz

Download URL deeply-1.0.3.tar.gz
Size 2.4 kB
Tags Source
SHA-256 checksum
How to use checksums
aa77d3fe99db85a9d98f2183fd2d1d081390e6d3341b7a86f73626cc1f7605ec
BLAKE2b-256 checksum
How to use checksums
ef02fed8a68a97b7887cf8cd468c29e5c3418799f2fbfff7e66a98fb9d6314d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.12.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.45.0 CPython/3.8.0

Security for deeply 1.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page