Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

travis-master coverall-master

dirty-validators

Agnostic validators for python 3

Freely based on [WTF-Forms](https://github.com/wtforms/wtforms) validators.

Features

  • Python 3 package.

  • Easy to create a validator.

  • Chained validations.

  • Conditional validations.

  • Specific error control messages.

  • Dirty model integration (https://github.com/alfred82santa/dirty-models)

  • No database dependent.

  • Asynchronous validators.

  • Stateless validators.

  • Deferred validators.

Changelog

Version 0.6.0

The stateless refactor. Dirty validators now are full stateless. It means now there is no messages on validator instance. The is_valid method returns a validation context. It is evaluated as True if there were no errors and false otherwise. So, it is possible to still to use checks like if validator.is_valid(my_data): but we recomend to use the Walruf operator (https://peps.python.org/pep-0572/): if result := validator.is_valid(my_data):. That is important because messages are stored on context.

# Python +3.8
if result := validator.is_valid(my_data):
    # some code
else:
    print(result.error_messages)

#or

if not (result := validator.is_valid(my_data)):
    print(result.error_messages)

On the other hand, validation error messages now are an object. It stores error code, error message template and context values. There is a helper function from_context_to_legacy_message in order to convert a context to legacy message format.

  • Stateless refactor

  • New Context class stores state of validation process.

  • New ValidationErrorMessage class to store validation error messages.

  • New Deferred validator in order to build validator on runtime depending on context.

  • New from_context_to_legacy_message helper.

Version 0.5.4

  • Allow model validator inheritance.

Version 0.5.2

  • Remove hard dependency from Dirty Models.

  • Fix bug iterating ListModels.

Version 0.5.1

  • Added value validators for mappings.

Version 0.5.0

  • Added asynchronous validators.

Version 0.4.0

  • Added <root> keyword in order to look up a field from root model of context.

  • Added key_validator argument for spec validators in order to validate keys on hashmaps.

Installation

$ pip install dirty-validators

Basic usage

from dirty_validators.basic import EqualTo, Length, Regexp, Email
from dirty_validators.complex import Optional, ModelValidate

validator = Optional(validators=[EqualTo(comp_value="test")])

assert validator.is_valid("test") is True

# Chained validation
validator_chain = Chain(validators=[Length(min=14, max=16), Regexp(regex='^abc'), Email()])

assert validator_chain.is_valid('abcdefg@test.com')

# Model validation

class MyModelValidator(ModelValidate):
    fieldName1 = Optional(validators=[Length(min=4, max=6)])
    fieldName2 = Optional(validators=[Length(min=1, max=2)])
    fieldName3 = Required(validators=[Length(min=7, max=8)])

validator_model = MyModelValidator()

data = {
    "fieldName1": "1234",
    "fieldName1": "12",
    "fieldName3": "123456qw"
 }

assert validator_model.is_valid(FakeModel(data)) is True

Metadata

Release files for dirty-validators 0.6.0b2

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

Built distribution (wheel)

Table of built distributions (wheels) for dirty-validators 0.6.0b2
File Interpreter ABI Platform
dirty_validators-0.6.0b2-py3-none-any.whl Python 3 none any Details

Release files / dirty_validators-0.6.0b2-py3-none-any.whl

Download URL dirty_validators-0.6.0b2-py3-none-any.whl
Size 16.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f82afa08ae199e5029ea5b2629cf8c545ea4641b5063e86d64c2b22e294855c3
BLAKE2b-256 checksum
How to use checksums
f1ea06c24f6019742cae794507095add94eed5daad72e33266439d8553ce0e5b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.2 readme-renderer/34.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.3 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.9.10

Release history Release notifications | RSS feed

This release

0.6.0b2 This release

1 release file

0.5.4

1 release file

0.5.3

1 release file

0.5.2

1 release file

0.5.1

1 release file

0.5.0

1 release file

0.4.0

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.6

1 release file

0.1.5

1 release file

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