Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (
Help us improve Python packaging - Donate today!

rest, restful validator aiohttp

Project Description

Wraps aiophtt, for validation and rapid construction of micro-services. pros: - Easy integration without affecting the operation of the entire project - Declarative description of the input parameters - The ability to validate asynchronously - Availability of methods for http


import asyncio

from aiohttp import web

from aiovalidator import (

async def foo_validator(value):
    await asyncio.sleep(1)
    return value

def foo_default(value):
    async def default():
        return value

    return default

class Hello(web.View):
    class Field:
        field1 = IntegerField()
        field2 = IntegerField(required=False, methods={'GET'},
                              verbose_name='Field method get')
        field3 = IntegerField(validator=foo_validator, )
        field4 = IntegerField(default=foo_default)

    def get(self):
        fields = self.request['fields']
        return web.json_response()

app = web.Application(middlewares=[validator_factory(), middleware_exception])
app.router.add_get('/{user_id}/', Hello)
web.run_app(app, port=8000)

My fields example

import phonenumbers
from aiovalidator import StrField, abort

class PhoneField(StrField):
    def get_value(self, value):
        value = super().get_value(value)
            value = phonenumbers.parse(value, 'RU')
            region = phonenumbers.region_code_for_number(value)
            regions = phonenumbers.COUNTRY_CODE_TO_REGION_CODE[7]
            if not phonenumbers.is_valid_number(value):
                raise abort(status=400,
                      text='Field {} not format phone'.format(
            if region not in regions:
                raise abort(status=400,
                      text='Field {} not format phone'.format(
            value = phonenumbers.format_number(
                value, phonenumbers.PhoneNumberFormat.E164

            return value
        except phonenumbers.NumberParseException:
            raise abort(status=400, text='Field {} not valid'.format(
Release History

Release History

This version
History Node


History Node


History Node


Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
aiovalidator-0.0.4.tar.gz (5.1 kB) Copy SHA256 Checksum SHA256 Source Jan 17, 2017

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting