Skip to main content

Python JSON schema validator with better error message

Project description

kanpai is a library for validating Python data structures, mainly those coverted from JSON. e.g. JSON received from api request, obtained from config file etc.


Here is a quick example

import kanpai as Kanpai

schema = Kanpai.Object({
        'first_name': (Kanpai.String(error='User first name must be string.')
                       .required(error='Please provide user first name.')
                       .max(256, error='Maximum allowed length is 256')),

        'last_name': (Kanpai.String(error='User last name must be a String')
                      .required(error='Please provide user last name.')),

        'age'      : (Kanpai.Number(error='Age must be a number.')
                      .max(35,'Maximum allowed age is 35')
                      .min(18,'Age must be minimum 18'))


validation_result = schema.validate({
  'age': 15

assert validation_result == {
  'success': False,
  'error': {
    'last_name': 'Please provide user last name.',
    'age': 'Age must be minimum 18'
  'data': {
     'age': 15

schema.validate return a dictionary obejct containing

 'success':'Whether validation is success or not',
 'error':'Validation error',
 'data':'Incase of error data provided for validation , in case success validated data'


Use pip

pip install kanpai


pytest # to run tests
pytest --cov-report=html  --cov-branch --cov=kanpai # to generate coverage report

Project details

Download files

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

Files for kanpai, version 0.1.11
Filename, size File type Python version Upload date Hashes
Filename, size kanpai-0.1.11-py3-none-any.whl (7.8 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size kanpai-0.1.11.tar.gz (4.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page