Skip to main content

A validation library for python using trafaret

Project description

https://travis-ci.org/Lex0ne/trafaret_validator.svg?branch=master https://coveralls.io/repos/github/Lex0ne/trafaret_validator/badge.svg?branch=master https://img.shields.io/pypi/v/trafaret_validator.svg https://img.shields.io/pypi/pyversions/trafaret_validator.svg

Install:

pip install trafaret_validator

This is a wrapper that validate params using Trafaret ( http://trafaret.readthedocs.org/en/latest/ ).

Usage:

import trafaret as t
from trafaret_validator import TrafaretValidator


def foo_validator(value):
    if value != 'foo':
        return t.DataError('Expected foo!')
    return 'foo'


class RequestValidator(TrafaretValidator):
    ids = t.List(t.Int)
    payload = t.Dict(foo=t.Call(foo_validator))

validator = RequestValidator(ids=ids, payload=payload)
if not validator.validate():
    return validator.errors

data = validator.data # returns checked dict of params {'ids': [...], 'payload': {'foo': 'foo'}}
ids = validator.ids
payload = validator.payload

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

trafaret_validator-0.4.0.tar.gz (3.1 kB view hashes)

Uploaded Source

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