Skip to content

Repository files navigation

validium

a Python utility library for performing validations flexibly

Installation

pip install validium

Quick Start

Here's an example of how to create and use some very simple validators for some numbers:

importvalidiumasVPI=3.14ONE=1is_number=V.Validator(lambdax: isinstance(x, Number), 'must be a number')
is_number.validate(PI) # passis_number.validate(ONE) # passis_positive=V.Validator(lambdax: x>0, 'must be positive')
is_positive.validate(PI) # passis_positive.validate(ONE) # passis_not_one=V.Validator(lambdax: notx==1, 'must not equal 1')
is_not_one.validate(PI) # passis_not_one.validate(ONE) # AssertionError: must not equal 1

Building Up

Here's an example of how to parameterize and reuse a common validator pattern:

is_not=lambday: V.Validator(lambdax: notx==y, 'must not equal {}'.format(x)) # uis_not(-1).validate(ONE) # passis_not(0).validate(ONE) # passis_not(1).validate(ONE) # AssertionError: must not equal 1

This approach will help keep your code nice and DRY in the event you need handful of validators that behave mostly the same but slightly different.

About

a functional library for creating validators in Python

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages