Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

dvalidator validation attributes

Project description

Library for validating your object dictionary

from dvalidator.validator import Validator
import dvalidator.rules as rules


validator = Validator({
    'a': rules.required(),
    'b': rules.required('Field "b" not found'),
    'c': [rules.required(), rules.is_type(str, 'Field "c" is not str type')]
    })

d = {'a': 1, 'b': 2, 'c': '3'}

res, err = validator.validate(d)

print(res)
True

Other rules see in: https://github.com/kakabara/capybara/blob/master/capybara/rules.py

Also you can create custom validation method:

from dvalidator.validator import Validator
import dvalidator.rules as rules


def raise_on_exist(message='Found unexpected field in dict'):
    def check(field: str, dict_to_check: dict):
        if field in dict_to_check:
            return False, None
        else:
            return True, message
    return check

validator = Validator({
    'a': rules.required(),
    'b': raise_on_exist()
    })

d = {'a': 1, 'b': 2}

res, err = validator.validate(d)

print(res)
False

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for dvalidator, version 0.1.4
Filename, size File type Python version Upload date Hashes
Filename, size dvalidator-0.1.4.tar.gz (3.1 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page