Skip to main content

Fast Python JSON schema validation and normalization

Project description

Fast Python JSON schema validation and normalization

v = Validator({
  'User': {
    'items': {
      'name': {'coerce': 'str'},
      'gender': {
        'map': {
          'woman': 'female',
          'man': 'male',
          None: 'other'  # Map everything else
        },
        'synonyms': ['sex']
      },
      'country': {
        'default': '{GEOIP2_COUNTRY}'
      }
    }
  }
})

args = {'GEOIP2_COUNTRY': 'UK'}

v['User']({
  'name': 123,
  'sex': 'woman'
}, args)

# Returns:
#
# ({
#    'name': '123',
#    'gender': 'female',
#    'country': 'UK'
#  },
#  None)  # Error description

Features

Pycoercer was created to meet the actual production needs for web apps development - inspired by jsonschema and Cerberus, it also implements additional features: - Can validate, normalize (or coerce) dicts and lists - Fast - the schema is compiled into python code - Clean rules system with a predictable order of execution - Parametric default and if_null values - Keywords for data coercion: synonyms, map, and post_coerce - Check examples against the schema definition

Installation

$ pip install pycoercer

Documentation

Complete documentation will be [sometime][docs]

Testing

$ pytest

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 pycoercer, version 0.1.2
Filename, size File type Python version Upload date Hashes
Filename, size pycoercer-0.1.2.tar.gz (7.4 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page