Skip to main content

dataclass & validation simple as well as hell.

Project description

Validata

Dataclass and validation made simple as well as powerful.

Installation

You can install Validata using pip:

pip install validata

To install from GitHub:

git clone https://github.com/MirS0bhan/validata && cd validata
pip install .

Usage

Basic Example

Here’s how to define a dataclass and use the validation features:

from vlidt import BaseModel

class A(BaseModel):
    x: int
    y: int

class B(A):
    z: list[str]

c = B(5, 6, ["abc", "xyz"])

Validation

You can validate the fields of your dataclass instances easily:

from vlidt import validate

# Validate the instance
is_valid = validate(c)
print(is_valid)  # Returns True if valid, otherwise False

Dumping and Loading Data

You can convert your dataclass instances to and from dictionaries:

# Dumping the instance to a dictionary
data_dict = dump(c)
print(data_dict)  # Output: {'x': 5, 'y': 6, 'z': ['abc', 'xyz']}

# Loading from a dictionary
new_instance = load(B, data_dict)
print(new_instance)  # Output: B(x=5, y=6, z=['abc', 'xyz'])

Nested Dataclasses

Validata supports nested dataclasses, allowing you to create more complex data structures:

class C(BaseModel):
    a: A
    additional_info: str

instance_c = C(a=c, additional_info="Some info")
print(instance_c)

Features

  • Automatic Validation: Validate dataclass fields with minimal effort.
  • Dump and Load: Easily convert dataclass instances to and from dictionaries.
  • Nested Support: Handle nested dataclass instances seamlessly.
  • Type Annotations: Leverage Python’s type hints for better code clarity and error checking.

Contributing

Contributions are welcome! If you would like to contribute to Validata, please follow these steps:

  • Fork the repository.
  • Create a new branch for your feature or bugfix.
  • Make your changes and commit them.
  • Push to your branch and submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for more details. Contact

For any inquiries or suggestions, feel free to reach out via GitHub Issues.

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

vlidt-0.2.1.tar.gz (3.1 kB view details)

Uploaded Source

Built Distribution

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

vlidt-0.2.1-py3-none-any.whl (4.4 kB view details)

Uploaded Python 3

File details

Details for the file vlidt-0.2.1.tar.gz.

File metadata

  • Download URL: vlidt-0.2.1.tar.gz
  • Upload date:
  • Size: 3.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.9.8-arch1-1

File hashes

Hashes for vlidt-0.2.1.tar.gz
Algorithm Hash digest
SHA256 6caaca5b5d17e44055746d1ebe22bf3d42b2f6a8c7d4dd7ad6b90c26ccea37c4
MD5 33d11a97375b21385df9711bafc01dc1
BLAKE2b-256 c2eba9285f06670df9ff0b7aadcd36c7289721ccb3f49111e8c15950983d25e2

See more details on using hashes here.

File details

Details for the file vlidt-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: vlidt-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 4.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Linux/6.9.8-arch1-1

File hashes

Hashes for vlidt-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ae2e8657ba476aab2be87c9c971ff0fa258521cb8885dd2c540aee838eb4d713
MD5 58e91f557bd2491337454bf5f2298994
BLAKE2b-256 f7dd673b498804ab5947618df32d4c7d47313d9843ca84aa61f474bf08df2547

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