Skip to main content

trafaret validator wrapper

Project description

Install:

pip install trafaret_validator
Status:

Beta

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

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

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.2.5.tar.gz (2.2 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