Skip to main content

A simple validation library

Project description

RATIFY

website: ratify
documentation: documentation

Ratify is a python based validator. It can be used to validate strings, integers, floats, lists and dicts.

make

The make method is used to validate data against a schema. The make method takes two arguments, data and rule. The data argument is the data that you want to validate, and the rule argument is the schema that you want to validate the data against.

The make method returns a dictionary with the validated data. If the data is invalid, the make method raises a ValidationError exception.

    from ratify.ratify import Ratify

    validator = Ratify()

    try:
        data = {
            "name": "John Doe",
            "email": "john@ratify.com",
            "age": 25
        }

        rule = {
            "name": ['required'],
            "email": ['required', 'email'],
            "age": ['required', 'integer', 'max:30']
        }

        validated = validator.make(data, rule)
    except ValidationError as e:
        print(e)

alpha

alpha

The alpha rule is used to check if a field contains only alphabetic characters. If the field contains any non-alphabetic characters, the alpha rule raises a ValidationError exception.

The alpha rule does not take any arguments.

from ratify.ratify import Ratify
validator = Ratify()

try:
    data = {
        "name": "John Doe",
    }

    rule = {
        "name": ['alpha'],
    }

    validated = validator.make(data, rule)
except ValidationError as e:
    print(e)

alpha_num

alpha_num

The alpha_num rule is used to check if a field contains only alphabetic and numeric characters. If the field contains any non-alphabetic or non-numeric characters, the alpha_num rule raises a ValidationError exception.

The alpha_num rule does not take any arguments.

from ratify.ratify import Ratify
validator = Ratify()

try:
    data = {
        "username": "JohnDoe657",
    }

    rule = {
        "username": ['alpha_num'],
    }

    validated = validator.make(data, rule)
except ValidationError as e:
    print(e)                    

after

after:date

The after rule is used to check if a date is after a specified date. If the date is not after the specified date, the after rule raises a ValidationError exception.

The after rule takes one argument, date, which is the date that the field should be after. The date argument should be in the format YYYY-MM-DD.

from ratify.ratify import Ratify
validator = Ratify()

try:
    data = {
        "start": "2024-10-20",
    }

    rule = {
        "start": ['after:2024-11-01'],
    }

    validated = validator.make(data, rule)
except ValidationError as e:
    print(e)                   

after_or_equal

after_or_equal:date

The after_or_equal rule is used to check if a date is after or equal to a specified date. If the date is not after or equal to the specified date, the after_or_equal rule raises a ValidationError exception.

The after_or_equal rule takes one argument, date, which is the date that the field should be after or equal to. The date argument should be in the format YYYY-MM-DD.

from ratify.ratify import Ratify
validator = Ratify()

try:
    data = {
        "start_date": "2024-10-20",
    }

    rule = {
        "start_date": ['after_or_equal:2024-11-01'],
    }

    validated = validator.make(data, rule)
except ValidationError as e:
    print(e)                   

before

before:date

The before rule is used to check if a date is before a specified date. If the date is not before the specified date, the before rule raises a ValidationError exception.

The before rule takes one argument, date, which is the date that the field should be before. The date argument should be in the format YYYY-MM-DD.

from ratify.ratify import Ratify
validator = Ratify()

try:
    data = {
        "deadline": "2024-10-20",
    }

    rule = {
        "deadline": ['after:2024-11-01'],
    }

    validated = validator.make(data, rule)
except ValidationError as e:
    print(e)                    

before_or_equal

before_or_equal:date

The before_or_equal rule is used to check if a date is before or equal to a specified date. If the date is not before or equal to the specified date, the before_or_equal rule raises a ValidationError exception.

The before_or_equal rule takes one argument, date, which is the date that the field should be before or equal to. The date argument should be in the format YYYY-MM-DD.

from ratify.ratify import Ratify
validator = Ratify()

try:
    data = {
        "deadline": "2024-10-20",
    }

    rule = {
        "deadline": ['before_or_equal:2024-11-01'],
    }

    validated = validator.make(data, rule)
except ValidationError as e:
    print(e)                    

boolean

boolean

The boolean rule is used to check if a field is a boolean value. If the field is not a boolean value, the boolean rule raises a ValidationError exception.

The boolean rule does not take any arguments.

from ratify.ratify import Ratify
validator = Ratify()

try:
    data = {
        "is_available": True
    }

    rule = {
        "is_available": ['boolean'],
    }

    validated = validator.make(data, rule)
except ValidationError as e:
    print(e)                 

confirm_password

confirm_password:password_field

The confirm_password rule is used to check if a field matches another field. If the field does not match the other field, the confirm_password rule raises a ValidationError exception.

The confirm_password rule takes one argument, password_field, which is the field that the field should match.

from ratify.ratify import Ratify
validator = Ratify()

try:
    data = {
        "enter_password": "1234Password ",
        "confirm_password": "1234Password "
    }

    rule = {
        "confirm_password": ['confirm_password:enter_password']
    }

    validated = validator.make(data, rule)
except ValidationError as e:
    print(e)                 

contains

contains:foo

The contains rule is used to check if a value exists in a list. If the list does not contain the specified value, the contains rule raises a ValidationError exception.

The contains rule takes one argument, value, which is the value that the list should contain.

from ratify.ratify import Ratify
validator = Ratify()

try:
    data = {
        "ages": [1, 2, 3, 4, 5]
    }

    rule = {
        "ages": ['contains:3']
    }

    validated = validator.make(data, rule)
except ValidationError as e:
    print(e)                 

date

date

The date rule is used to check if a field is a valid date. If the field is not a valid date, the date rule raises a ValidationError exception.

The date rule does not take any arguments.

from ratify.ratify import Ratify
validator = Ratify()

try:
    data = {
        "start_date": "2024-10-20"
    }

    rule = {
        "start_date": ['date']
    }

    validated = validator.make(data, rule)
except ValidationError as e:
    print(e)                 

date_format

date_format:format

The date_format rule is used to check if a field is a valid date with a specified format. If the field is not a valid date with the specified format, the date_format rule raises a ValidationError exception.

The date_format rule takes one argument, format, which is the format that the date should be in. The format argument should be a valid date format string.

from ratify.ratify import Ratify
validator = Ratify()

try:
    data = {
        "start_date": "10-20-2024"
    }

    rule = {
        "start_date": ['date_format:%m-%d-%Y']
    }

    validated = validator.make(data, rule)
except ValidationError as e:
    print(e)                 

datetime

datetime

The datetime rule is used to check if a field is a valid datetime. If the field is not a valid datetime, the datetime rule raises a ValidationError exception.

The datetime rule does not take any arguments.

from ratify.ratify import Ratify
validator = Ratify()

try:
    data = {
        "start_date": "2024-10-20 12:30:05"
    }

    rule = {
        "start_date": ['datetime']
    }

    validated = validator.make(data, rule)
except ValidationError as e:
    print(e)                 

dict

dict

The dict rule is used to check if a field is a valid dictionary. If the field is not a valid dictionary, the dict rule raises a ValidationError exception.

The dict rule takes no argument

from ratify.ratify import Ratify
validator = Ratify()

try:
    data = {
        "inventory": {"name": "John Doe", "age": 23, "country": "Nigeria"}
    }

    rule = {
        "inventory": ['dict']
    }

    validated = validator.make(data, rule)
except ValidationError as e:
    print(e)

email

email

The email rule is used to check if a field is a valid email address. If the field is not a valid email address, the email rule raises a ValidationError exception.

The email rule does not take any arguments.

from ratify.ratify import Ratify
validator = Ratify()

try:
    data = {
        "email_address": "john@ratify.com",
    }

    rule = {
        "email_address": ['email'],
    }

    validated = validator.make(data, rule)
except ValidationError as e:
    print(e)

ends_with

ends_with:foo

The ends_with rule is used to check if a field ends with a specified value. If the field does not end with the specified value, the ends_with rule raises a ValidationError exception.

The ends_with rule takes one argument, foo, which is the value that the field should end with.

from ratify.ratify import Ratify
validator = Ratify()

try:
    data = {
        "name": "Jones",
    }

    rule = {
        "name": ['ends_with:es'],
    }

    validated = validator.make(data, rule)
except ValidationError as e:
    print(e)

file

file:extensions

The file rule checks if the file is a valid file and if the file has the specified extensions. If the file is not valid or does not have the specified extensions, the file rule raises a ValidationError exception.

The file rule takes one argument, extensions, which is a comma-separated list of file extensions that the file should have.

note: The file rule only works with the Flask file object

from ratify.ratify import Ratify
validator = Ratify()

try:
    data = {
        "cv": "document.pdf",
    }

    rule = {
        "cv": ['file:pdf,txt,doc'],
    }

    validated = validator.make(data, rule)
except ValidationError as e:
    print(e)

float

float

The float rule is used to check if a field is a valid float. If the field is not a valid float, the float rule raises a ValidationError exception.

The float rule does not take any arguments.

from ratify.ratify import Ratify
validator = Ratify()

try:
    data = {
        "price": 24.32,
    }

    rule = {
        "price": ['float']
    }

    validated = validator.make(data, rule)
except ValidationError as e:
    print(e)

greater_than

greater_than:another_field

The greater_than rule is used to check if a field is greater than another field. If the field is not greater than the specified field, the greater_than rule raises a ValidationError exception.

The greater_than rule takes one argument, another_field, which is the referenced field.

from ratify.ratify import Ratify
validator = Ratify()

try:
    data = {
        "age_limit": 20,
        "age": 24,
    }

    rule = {
        "age": ['greater_than:age_limit'],
    }

    validated = validator.make(data, rule)
except ValidationError as e:
    print(e)

greater_than_or_equal

greater_than_or_equal:another_field

The greater_than_or_equal rule is used to check if a field is greater than or equal to another field. If the field is not greater than or equal to the specified field, the greater_than_or_equal rule raises a ValidationError exception.

The greater_than_or_equal rule takes one argument, another_field, which is the referenced field.

from ratify.ratify import Ratify
validator = Ratify()

try:
    data = {
        "age_limit": 20,
        "age": 20,
    }

    rule = {
        "age": ['greater_than:age_limit'],
    }

    validated = validator.make(data, rule)
except ValidationError as e:
    print(e)

in

in:foo,bar...

The in rule is used to check if a field is in a list of comma separated values. If the field is not in the list of values, the in rule raises a ValidationError exception.

The in rule takes one argument, "foo, bar", which is a comma-separated list of values that the field should be in.

from ratify.ratify import Ratify
validator = Ratify()

try:
    data = {
        "age": 20
    }

    rule = {
        "age": ['in:20,21,23,25']
    }

    validated = validator.make(data, rule)
except ValidationError as e:
    print(e)

integer

integer

The integer rule checks if a field contains a valid integer

The integer rule takes no argument

from ratify.ratify import Ratify
validator = Ratify()

try:
    data = {
        "age": 20
    }

    rule = {
        "age": ['integer']
    }

    validated = validator.make(data, rule)
except ValidationError as e:
    print(e)

less_than

less_than:another_field

The less_than rule checks if the field under validation is less than the value in another field

The less_than rule takes one argument, another_field, which is the referenced field.

from ratify.ratify import Ratify
validator = Ratify()

try:
    data = {
        "wallet_balance": 20000,
        "price": 5000
    }

    rule = {
        "price": ['less_than:wallet_balance']
    }

    validated = validator.make(data, rule)
except ValidationError as e:
    print(e)

less_than_or_equal

less_than_or_equal:another_field

The less_than_or_equal rule checks if the field under validation is less than or equals a value in another field

The less_than_or_equal rule takes one argument, another_field, which is the referenced field.

from ratify.ratify import Ratify
validator = Ratify()

try:
    data = {
        "wallet_balance": 20000,
        "price": 5000
    }

    rule = {
        "price": ['less_than_or_equal:wallet_balance']
    }

    validated = validator.make(data, rule)
except ValidationError as e:
    print(e)

list

list

The list rule verifies if a value is a valid list

The list rule takes no argument.

from ratify.ratify import Ratify
validator = Ratify()

try:
    data = {
        "students": ['Joy', 'Joel', 'Kenn', 'Kay']
    }

    rule = {
        "students": ['list']
    }

    validated = validator.make(data, rule)
except ValidationError as e:
    print(e)

lowercase

lowercase

The lowercase rule checks if all the characters in a value are all lowercases.

The lowercase rule does not take any argument

from ratify.ratify import Ratify
validator = Ratify()

try:
    data = {
        "model": "tedds"
    }

    rule = {
        "model": ['lowercase']
    }

    validated = validator.make(data, rule)
except ValidationError as e:
    print(e)

max

max:maximum_value

The max rule is used to check if a field's value is less than or equal to a specified minimum value. If the field's value is less than the specified minimum value, the min rule raises a ValidationError exception.

The max rule takes one argument, maximum_value, which is the maximum value that the field should have.

from ratify.ratify import Ratify
validator = Ratify()

try:
    data = {
        "password": "1234Point"
    }

    rule = {
        "password": ['max:12']
    }

    validated = validator.make(data, rule)
except ValidationError as e:
    print(e)

mimes

mimes:foo,bar....

The mimes rule is used to check if a file has a specified MIME type. If the file does not have the specified MIME type, the mimes rule raises a ValidationError exception.

The mimes rule takes comma seperated arguments, which are the MIME types that the file should have.

from ratify.ratify import Ratify
validator = Ratify()

try:
    data = {
        "photo": "selfie.jpg"
    }

    rule = {
        "photo": ['mimes:jpg,png']
    }

    validated = validator.make(data, rule)
except ValidationError as e:
    print(e)

min

min:minimum_value

The min rule is used to check if a field's value is greater than or equal to a specified minimum value. If the field's value is less than the specified minimum value, the min rule raises a ValidationError exception.

The min rule takes one argument, minimum_value, which is the minimum value that the field should have.

from ratify.ratify import Ratify
validator = Ratify()

try:
    data = {
        "password": "1234Point"
    }

    rule = {
        "password": ['min:6']
    }

    validated = validator.make(data, rule)
except ValidationError as e:
    print(e)

not_in

not_in:foo,bar...

The not_in rule is used to check if a field is not in a list of comma-separated values. If the field is in the list of values, the not_in rule raises a ValidationError exception.

The not_in rule takes one argument, "foo, bar", which is a comma-separated list of values that the field should not be in.

from ratify.ratify import Ratify
validator = Ratify()

try:
    data = {
        "weekday": "monday"
    }

    rule = {
        "weekday": ['not_in:sunday,saturday']
    }

    validated = validator.make(data, rule)
except ValidationError as e:
    print(e)

required

required

The required rule is used to check if a field is present in the data. If the field is not present, the required rule raises a ValidationError exception.

The required rule does not take any arguments.

from ratify.ratify import Ratify
validator = Ratify()

try:
    data = {
        "name": "John Doe",
        "email": "john@ratify.com",
        "age": 25
    }

    rule = {
        "name": ['required'],
        "email": ['required'],
        "age": ['required']
    }

    validated = validator.make(data, rule)
except ValidationError as e:
    print(e)

required_if

required_if:another_field,foo..

The required_if rule makes a field required when a specified field contains a specified value

The required_if rule takes a comma seperated argument which starts with the referenced field as the first value, then the specified values

from ratify.ratify import Ratify
validator = Ratify()

try:
    data = {
        "name": "John Doe",
        "country": "Canada",
        "zip_code": "100 WYM",
        "email": "john@ratify.com",
        "age": 25
    }

    rule = {
        "zip_code": ['required_if:country,Canada,USA']
    }

    validated = validator.make(data, rule)
except ValidationError as e:
    print(e)

same

same:another_field

The same rule is used to check if a field matches another field. If the field does not match the other field, the same rule raises a ValidationError exception.

The same rule takes one argument, another_field, which is the field that the field should match.

from ratify.ratify import Ratify
validator = Ratify()

try:
    data = {
        "email": "john@ratify.com",
        "confirm_email": "john@ratify.com"
    }

    rule = {
        "confirm_email: ['same:email']
    }

    validated = validator.make(data, rule)
except ValidationError as e:
    print(e)

size

size:value

The size rule is used to check if a field's value is equal to a specified size. If the field's value is not equal to the specified size, the size rule raises a ValidationError exception.

This validates integers, strings and lists. when used on integers, the field under validation must be equal to the specified value, for strings it validates the string's length, for lists it validates the list length.

The size rule takes one argument, value, which is the specified value

from ratify.ratify import Ratify
validator = Ratify()

try:
    data = {
        "age": 20,
        "key": "Everyday",
        "names": ["Rahman", "Kola", "Chike"]
    }

    rule = {
        "age": ['size:20'],
        "key": ['size:8'],
        "names": ['size:3']
    }

    validated = validator.make(data, rule)
except ValidationError as e:
    print(e)

starts_with

starts_with:value

The starts_with rule checks if a field starts with a specified value. If the field does not start with the specified value, the starts_with rule raises a ValidationError exception.

The starts_with rule takes one argument, value, which is the value that the field should start with.

from ratify.ratify import Ratify
validator = Ratify()

try:
    data = {
        "name": "Everyday"
    }

    rule = {
        "name": ['starts_with:Ev']
    }

    validated = validator.make(data, rule)
except ValidationError as e:
    print(e)

string

string

The string rule checks if a field is a valid string. If the field is not a valid string, the string rule raises a ValidationError exception.

The string rule takes no argument

from ratify.ratify import Ratify
validator = Ratify()

try:
    data = {
        "name": "Everyday19"
    }

    rule = {
        "name": ['string']
    }

    validated = validator.make(data, rule)
except ValidationError as e:
    print(e)

uppercase

uppercase

The uppercase rule checks if all the characters in a value are all uppercases.

The uppercase rule does not take any argument

from ratify.ratify import Ratify
validator = Ratify()

try:
    data = {
        "model": "TEDDS"
    }

    rule = {
        "model": ['uppercase']
    }

    validated = validator.make(data, rule)
except ValidationError as e:
    print(e)                         

url

url

The url rule checks if a field is a valid URL. If the field is not a valid URL, the url rule raises a ValidationError exception.

The url rule does not take any argument

from ratify.ratify import Ratify
validator = Ratify()

try:
    data = {
        "website": "https://ted.com"
    }

    rule = {
        "webiste": ['url']
    }

    validated = validator.make(data, rule)
except ValidationError as e:
    print(e)                         

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

ratify-0.3.0.tar.gz (15.6 kB view details)

Uploaded Source

Built Distribution

ratify-0.3.0-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file ratify-0.3.0.tar.gz.

File metadata

  • Download URL: ratify-0.3.0.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for ratify-0.3.0.tar.gz
Algorithm Hash digest
SHA256 5734afabad89ab1d9101418aa5a75c9af40497dc57bd728d764ef71b7f753386
MD5 20a22153df1f357682ba53592f2a5c64
BLAKE2b-256 02636afce313030af81ae69da1b05681ea01451c1fa1687acabea523f06f1015

See more details on using hashes here.

File details

Details for the file ratify-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: ratify-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.12

File hashes

Hashes for ratify-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 268a8b8d23c6d05b7505b858049db1cb2071f0622c94361f57f0687f0c6f4098
MD5 d3cf85e8eb004e222257134519cfee0f
BLAKE2b-256 149732ccc8a0df4c5b12b1aed0d9d7c8505ea32bd866368233345236bcc7bc29

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page