Skip to main content

dataclass_plus

Python 3.6 pypi travis-badge Coverage Status

The dataclass_plus is a fastest type validation library for the dataclass

Install

pip install dataclass-plus

Example

Basic Example

from dataclass_plus import dataclass_plus
from typing import List, Dict, Tuple


@dataclass_plus
class Model:
    id: int
    name: str
    dict_example: Dict[str, str]
    list_example: List[int] # this field is required
    tuple_example: Tuple[str, float] = None # this field is not required because set default None


Model(
    id=1, 
    name='Test Test', 
    dict_example={"test": "test"}, 
    list_example=[1,2],
    tuple_example=("test", 1.2)
)
# => Model(id=1, name='Test Test', dict_example={"test": "test"}, list_example=[1,2], tuple_example=("test", 1.2))

# Invalid Model
Model(
    id=1, 
    name='Test Test', 
    dict_example={"test": 1}, 
    list_example=[1,2],
    tuple_example=("test", 1.2)
)
# => TypeError: {'test': 1} is not typing.Dict[str, str]

Nested Example

from dataclass_plus import dataclass_plus
from typing import List, Dict, Tuple


@dataclass_plus
class Model:
    nested_example: List[List[str]]
    multi_nested_example: Dict[str, List[Tuple[str, List[int]]]]


Model(
    nested_example=[["test"], ["test_2"]],
    multi_nested_example={"test": [("test",[1, 2])]}
)
# => Model(nested_example=[['test'], ['test_2']], multi_nested_example={'test': [('test', [1, 2])]})

# Invalid Model
Model(
    nested_example=[["test"], ["test_2"]],
    multi_nested_example={"test": [("test",[1, "test"])]}
)
# => TypeError: [1, 'test'] is not typing.List[int]

Note: Can use every feature of dataclass (Example: frozen=True, init=True ...)

Metadata

Release files for dataclass-plus 2.0.0

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

Source distribution (sdist)

Source distribution for dataclass-plus 2.0.0
File Size Uploaded Provenance Actions
dataclass_plus-2.0.0.tar.gz 5.4 kB Without provenance Details for dataclass_plus-2.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for dataclass-plus 2.0.0
File Interpreter ABI Platform Actions
dataclass_plus-2.0.0-py3-none-any.whl Python 3 none any Details for dataclass_plus-2.0.0-py3-none-any.whl

Total release size: 23.0 kB

Release files / dataclass_plus-2.0.0.tar.gz

Download URL dataclass_plus-2.0.0.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
d9a8d3bfbbf1cf8b221aff15a6d1d91894f60260dcea9a6d164615c016d7689b
BLAKE2b-256 checksum
How to use checksums
01a31c43bf47d1cd816ce94ef06c10a78946592fff69c011cb35c7916295273e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.0

Release files / dataclass_plus-2.0.0-py3-none-any.whl

Download URL dataclass_plus-2.0.0-py3-none-any.whl
Size 17.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b2a7955aefa9a8b5ab1de8f528034561476c379f78d53c9d870e95ff9d369275
BLAKE2b-256 checksum
How to use checksums
4336866a588f28fb2a4f5df6fe06852646f5f44f29e8289c7a79945ca5f500bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.0

Security for dataclass-plus 2.0.0

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