Validators

Built in validators

These validators are provided with odin.

class odin.validators.RegexValidator(regex=None, message=None, code=None)[source]
class odin.validators.URLValidator(regex=None, message=None, code=None)[source]
class odin.validators.MaxValueValidator(limit_value)[source]
class odin.validators.MinValueValidator(limit_value)[source]
class odin.validators.LengthValidator(limit_value)[source]
class odin.validators.MaxLengthValidator(limit_value)[source]
class odin.validators.MinLengthValidator(limit_value)[source]

Odin also includes a helper method for generating simple validators.

odin.validators.simple_validator(assertion=None, message='The supplied value is invalid', code='invalid')[source]

Create a simple validator.

Parameters:
  • assertion – An Validation exception will be raised if this check returns a none True value.
  • message – Message to raised in Validation exception if validation fails.
  • code – Code to included in Validation exception. This can be used to customise the message at the resource level.

Usage:

>>> none_validator = simple_validator(lambda x: x is not None, message="This value cannot be none")

This can also be used as a decorator:

@create_validator(message="This value cannot be none")
def none_validator(v):
    return v is not None