Metadata-Version: 1.1
Name: pythonish-validator
Version: 0.4.0
Summary: Pythonish object scheme validator
Home-page: https://github.com/bugov/pythonish-validator
Author: Georgy Bazhukov
Author-email: georgy.bazhukov@gmail.com
License: BSD
Description: pythonish-validator
        ===================
        
        .. figure:: https://travis-ci.org/bugov/pythonish-validator.svg?branch=master
        
        Data validation library for Python without complex schemas.
        It's how you write Python code:
        
        🐍 Works with Python >= 3.7
        
        .. code:: bash
        
                from pythonish_validator.common import Validator
        
                validator = Validator({
                    'name': str,
                    'age': int,
                    'skills': [str]
                })
        
                validator.is_valid({
                    'name': 'Georgy',
                    'age': 29,
                    'skills': ['Python', 'Perl', 'C']
                })
        
        
        What can be easier?
        
        Install
        -------
        
        .. code:: bash
        
                pip3 install pythonish-validator
        
        Error messages
        --------------
        
        .. code:: bash
        
                from pythonish_validator.common import validate
        
                validator = validate({
                    'name': str,
                    'age': int,
                    'skills': [str]
                }, {
                    'name': 'Georgy',
                    'age': None,
                    'skills': ['Python', 'Perl', 42]
                })
        
                assert validator.repr_errors() == [
                    "{'age'}->NoneType(None)",
                    "{'skills'}->[2]->int(42)"
                ]
        
        Features
        --------
        
        🗣️ Speak the language of Python classes:
        
        .. code:: bash
        
                from pythonish_validator.common import Validator
        
        
                class User:
                    __validation_schema__ = {
                        'id': int,
                        'name': str
                    }
        
        
                validator = Validator({
                    "users": [User]
                })
        
                # valid structure
                validator.is_valid({
                    "users": [
                        {'id': 1, 'name': 'Alice'},
                        {'id': 2, 'name': 'Bob'},
                    ]
                })
        
                # invalid structure
                validator.is_valid({
                    "users": [
                        {'id': '1', 'name': 'Alice'},
                        {'id': 2},
                    ]
                })
        
                assert validator.repr_errors() == [
                    "{'users'}->[0]->{'id'}->str('1')",
                    "{'users'}->[1]->{'name'}",
                ]
        
        🎓 And even custom validation:
        
        .. code:: bash
        
                import re
        
                from pythonish_validator.common import Validator
        
        
                class EmailType:
                    @staticmethod
                    def __validation_schema__(data):
                        if not isinstance(data, str):
                            return False
        
                        if re.match(r'\w+@\w+.\w{2,5}', data) is None:
                            return False
        
                        return True
        
        
                class User:
                    __validation_schema__ = {
                        'id': int,
                        'name': str,
                        'email': EmailType,
                    }
        
        
                validator = Validator({
                    "users": [User]
                })
        
                validator.is_valid({
                    "users": [
                        {'id': 1, 'name': 'Alice', 'email': 'alice@example.com'},
                        {'id': 2, 'name': 'Bob', 'email': 'bob@example.com'},
                    ]
                })
        
        If you find any mistake – please write to the issue list 🐨 (https://github.com/bugov/pythonish-validator/issues).
        
Keywords: validator data check structure scheme
Platform: UNKNOWN
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.7
