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 details)

Uploaded Source

File details

Details for the file trafaret_validator-0.4.0.tar.gz.

File metadata

File hashes

Hashes for trafaret_validator-0.4.0.tar.gz
Algorithm Hash digest
SHA256 321e32d9a79cce82dcccca06e5bb95a82b76eb93a1bce647917878a0b59818d2
MD5 2cf74662fb64a060af92e4214046afdd
BLAKE2b-256 c7a204215bcf2e0dbe68a28e1323b1341246b9393dd27aa1398f2e0c3a4cd5e5

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