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!

JSON schema definition helpers

Project Description

Helpers to build you define JSON schema for either validation or publication.


It requires Python 2.7 and jsonschema. jsonschema or setuptools should be installed with Python.


Using pip:

pip install schemabuilder

Or easy_install:

easty_install schemabuilder

You may install it manually:

git clone
cd schemabuilder
python install



JSON schema primitives are represented by object of type:

  • schemabuilder.Str
  • schemabuilder.Bool
  • schemabuilder.Number
  • schemabuilder.Int
  • schemabuilder.Object
  • schemabuilder.Array
>>> import schemabuilder as jsb
>>> import pprint
>>> name = jsb.Str(pattern="^[a-zA-Z][- 'a-zA-Z0-9]+")
>>> email = jsb.Str(format="email")
>>> user = jsb.Object(properties={
...   'name': name(required=True),
...   'email': email(),
...   'home': jsb.Str(format='uri'),
... })
>>> pprint.pprint(user.to_dict())
{'properties': {'email': {'type': 'string'},
                'home': {'format': 'uri', 'type': 'string'},
                'name': {'type': 'string'}},
 'required': ['name'],
 'type': 'object'}


Schema collects those definitions for validation (using jsonschema) or publication.

>>> import schemabuilder as jsb
>>> import pprint
>>> my_schemas = jsb.Schema(id='')
>>> name = my_schemas.define(
...   'name', jsb.Str(pattern="^[a-zA-Z][- 'a-zA-Z0-9]+")
... )
>>> email = my_schemas.define('email', jsb.Str(format="email"))
>>> user = my_schemas.define('user', jsb.Object(properties={
...   'name': name(required=True),
...   'email': email(required=True),
... }))
>>> user.validate({'name': 'bob'})
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "schemabuilder/", line 50, in validate
  File "/Users/bob/pyenv/lib/python2.7/site-packages/jsonschema/", line 117, in validate
    raise error
jsonschema.exceptions.ValidationError: 'email' is a required property

Failed validating 'required' in schema:
    {'properties': {'email': {'$ref': '#/definitions/email'},
                    'name': {'$ref': '#/definitions/name'}},
     'required': ['name', 'email'],
     'type': 'object'}

On instance:
    {'name': 'bob'}
>>> user.validate({'name': 'bob', 'email': ''})
>>> import json
>>> print json.dumps(my_schemas.to_dict(), indent=4)
    "definitions": {
        "email": {
            "type": "string",
            "format": "email"
        "user": {
            "required": [
            "type": "object",
            "properties": {
                "name": {
                    "$ref": "#/definitions/name"
                "email": {
                    "$ref": "#/definitions/email"
        "name": {
            "pattern": "^[a-zA-Z][- 'a-zA-Z0-9]+",
            "type": "string"
    "id": "",
    "$schema": ""

Release History

This version
History Node


History Node


History Node


History Node


Download Files

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

Filename, Size & Hash SHA256 Hash Help File Type Python Version Upload Date
(7.1 kB) Copy SHA256 Hash SHA256
Source None Jan 6, 2015

Supported By

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 Google Google Cloud Servers