Skip to main content

Python Data Classes support Python 2 and 3 with many human-friendly features.

This project has been tested in Python 2.7 and Python 3.4+. It is not related to the dataclasses module introduced in Python 3.7.

Feature Support

Python Data Classes generally support

  • untyped data, typed data, and typed data list

  • arbitrary attribute names in the dictionary input

  • no python attribute naming conflict or pollution

  • lazy and auto object creation on-the-fly

  • lazy loading of the dict input (default: enabled)

  • synchronous updates of the dict input (default: disabled)

Getting Started

  • Install the Python Data Classes

pip install pydataclasses
  • Create the Python Data Classes

from pydataclasses import DataClass


class TT(DataClass):

    attr = None


class ONCE(DataClass):

    data = None


class TWICE(ONCE):

    tear = TT
    tears = [TT]

    def __init__(self, *args, **kwargs):

        super(TWICE, self).__init__(*args, **kwargs)

        self.pair = TWICE
        self.pairs = [TWICE]
  • Play with the Python Data Classes

old_data = 'hello'
new_data = 'world'
old_dict = {'data': old_data}
new_dict = {'data': new_data}

# lazy and auto object creation on-the-fly
twice = TWICE()
assert twice.pairs[1].tear.attr is None
twice.pairs[1].tear.attr = old_data
assert old_data == twice.pairs[1].tear.attr

# lazy loading of the dict input (default: enabled)
twice = TWICE(old_dict)
assert old_data == twice.data
assert old_dict == twice.__as_dict__(dict, 0)

# synchronous updates of the dict input (default: disabled)
assert old_dict != new_dict
twice = TWICE(old_dict, __sync__=True)
twice.data = new_data
assert old_dict == new_dict

Best Practices

Please

  • read and refer to pydataclasses.utils.JSONData as an example

  • put a tailored subclass between pydataclasses and your project

  • write (or copy from pydataclasses) as many tests as possible for this subclass

from pydataclasses import DataClass


class ProjectDataClass(DataClass):

    def as_dict(self, dict_class=OrderedDict):
        return self.__as_dict__(dict_class, 0)

Release History

1.0.1 (2019-05-04)

  • Bump the version again

1.0.1 (2019-05-04)

  • Bump the version

1.0.0 (2019-05-04)

  • Support the annotations of native dataclasses

0.0.2 (2018-08-28)

  • Fix the python packaging issues

  • Add the tox, pylint, pytest, coverage tools

0.0.1 (2018-08-26)

  • Birthday

Metadata

Release files for pydataclasses 1.0.2

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

Source distribution (sdist)

Source distribution for pydataclasses 1.0.2
File Size Uploaded Provenance Actions
pydataclasses-1.0.2.tar.gz 18.8 kB Without provenance Details for pydataclasses-1.0.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pydataclasses 1.0.2
File Interpreter ABI Platform Actions
pydataclasses-1.0.2-py3-none-any.whl Python 3 none any Details for pydataclasses-1.0.2-py3-none-any.whl

Total release size: 31.8 kB

Release files / pydataclasses-1.0.2.tar.gz

Download URL pydataclasses-1.0.2.tar.gz
Size 18.8 kB
Tags Source
SHA-256 checksum
How to use checksums
a9ee3de69d18c0a46ab790a844154b2ed8f4b109176b0590b456441305bcc2de
BLAKE2b-256 checksum
How to use checksums
82e79a8d3fdca8b9c1a4b349f56d534b65b6b90b917aacc705eaf67a8505308e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

Release files / pydataclasses-1.0.2-py3-none-any.whl

Download URL pydataclasses-1.0.2-py3-none-any.whl
Size 13.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bdf1da95e3f6e24ad02cf3f3da91767c08e1fd7f51d845a08bb543d319ad6765
BLAKE2b-256 checksum
How to use checksums
7f4773090af1542892989d4ae181a60fc31f83d0472003f94f2778e5beca778c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.3

Security for pydataclasses 1.0.2

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