Skip to main content

Builder-like data validation package

Project description

Ez Validate

Simple package for data validation.

Examples:

Valid

var = 10.0
ValidateThat(var).is_float().less_than(12.4).greater_than(9.2)

Invalid

var = 5.0
ValidateThat(var).is_float().less_than(12.4).greater_than(9.2)

This example will raise ValidationError with the following message:

"Untitled var" must be greater than 9.2 but is 5.0

You can change the the name of variable by providing it in ValidateThat constractor:

ValidateThat(var, name='Your name').is_float().less_than(12.4).greater_than(9.2)

Your name must be greater than 9.2 but is 5.0

To handle the error use try except clause:

try:
	...
except ValidationError as e:
	...

Multiple conditions

And condition:

ValidateThat(var).firts_condition().second_condition().third_condition()

Or condition:

either(
	lambda: ValidateThat(var).first_condition(),
	lambda: ValidateThat(var).second_condition(),
	lambda: ValidateThat(var).third_condition()
)

You can make combination of and and or conditions:

var = 1.5
either(
	lambda: ValidateThat(var).is_float().less_than(3.0).greater_than(0.0),
	lambda: ValidateThat(var).is_int().less_than(3).greater_than(0),
	lambda: ValidateThat(var).is_none()
)

That would mean var must be:

  • float and greater than 0 and less than 3.0
  • or
  • int and greater than 0 and less than 3
  • or
  • None

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

ez_validate-0.1.0.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

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

ez_validate-0.1.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

Details for the file ez_validate-0.1.0.tar.gz.

File metadata

  • Download URL: ez_validate-0.1.0.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for ez_validate-0.1.0.tar.gz
Algorithm Hash digest
SHA256 583992ea95c6adda0ae671158d8522d5150d14f77ee2d27ca68dbeb6f0a89fe1
MD5 0b46810e802e2eb431ffe8792b410026
BLAKE2b-256 e69ac76ffb513d369a05963ecb188b885d07ceae1ac8ec76c616a8d456eb5729

See more details on using hashes here.

File details

Details for the file ez_validate-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ez_validate-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for ez_validate-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 086d81a74eaf246abd298bf4f434b55a07f373d1c8337343080d0ab72bb343ab
MD5 f9bc62491b916bd9c8891b77e61cdc1b
BLAKE2b-256 67afd57b5982cc32e68a8e0d5a6bb2ee0ddf6ed3cdb3dbeda0023eecddfb7b39

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