validictory module#

As of 2018 this library is deprecated, please consider using jsonschema instead.

validate#

validictory.validate(data, schema, validator_cls=<class 'validictory.validator.SchemaValidator'>, format_validators=None, required_by_default=True, blank_by_default=False, disallow_unknown_properties=False, apply_default_to_data=False, fail_fast=True, remove_unknown_properties=False)#

Validates a parsed json document against the provided schema. If an error is found a ValidationError is raised.

If there is an issue in the schema a SchemaError will be raised.

Parameters:
  • data – python data to validate

  • schema – python dictionary representing the schema (see Schema Options)

  • validator_cls – optional validator class (default is SchemaValidator)

  • format_validators – optional dictionary of custom format validators

  • required_by_default – defaults to True, set to False to make required schema attribute False by default.

  • disallow_unknown_properties – defaults to False, set to True to disallow properties not listed in the schema definition

  • apply_default_to_data – defaults to False, set to True to modify the data in case the schema definition includes a “default” property

  • fail_fast – defaults to True, set to False if you prefer to get all validation errors back instead of only the first one

  • remove_unknown_properties – defaults to False, set to True to filter out properties not listed in the schema definition. Only applies when disallow_unknown_properties is False.

SchemaValidator#

class validictory.SchemaValidator(format_validators=None, required_by_default=True, blank_by_default=False, disallow_unknown_properties=False, apply_default_to_data=False, fail_fast=True, remove_unknown_properties=False)#

Bases: object

Validator largely based upon the JSON Schema proposal but useful for validating arbitrary python data structures.

Parameters:
  • format_validators – optional dictionary of custom format validators

  • required_by_default – defaults to True, set to False to make required schema attribute False by default.

  • blank_by_default – defaults to False, set to True to make blank schema attribute True by default.

  • disallow_unknown_properties – defaults to False, set to True to disallow properties not listed in the schema definition

  • apply_default_to_data – defaults to False, set to True to modify the data in case the schema definition includes a “default” property

  • fail_fast – defaults to True, set to False if you prefer to get all validation errors back instead of only the first one

  • remove_unknown_properties – defaults to False, set to True to filter out properties not listed in the schema definition. Only applies when disallow_unknown_properties is False.

validate_type(x, fieldname, schema, path, fieldtype=None)#

Validates that the fieldtype specified is correct for the given data

validate_properties(x, fieldname, schema, path, properties=None)#

Validates properties of a JSON object by processing the object’s schema recursively

validate_items(x, fieldname, schema, path, items=None)#

Validates that all items in the list for the given field match the given schema

validate_required(x, fieldname, schema, path, required)#

Validates that the given field is present if required is True

validate_blank(x, fieldname, schema, path, blank=False)#

Validates that the given field is not blank if blank=False

validate_additionalProperties(x, fieldname, schema, path, additionalProperties=None)#

Validates additional properties of a JSON object that were not specifically defined by the properties property

validate_minimum(x, fieldname, schema, path, minimum=None)#

Validates that the field is longer than or equal to the minimum length if specified

validate_maximum(x, fieldname, schema, path, maximum=None)#

Validates that the field is shorter than or equal to the maximum length if specified.

validate_maxProperties(x, fieldname, schema, path, number=None)#

Validates that the number of properties of the given object is less than or equal to the specified number

validate_minProperties(x, fieldname, schema, path, number=None)#

Validates that the number of properties of the given object is greater than or equal to the specified number

validate_maxLength(x, fieldname, schema, path, length=None)#

Validates that the value of the given field is shorter than or equal to the specified length

validate_minLength(x, fieldname, schema, path, length=None)#

Validates that the value of the given field is longer than or equal to the specified length

validate_minItems(x, fieldname, schema, path, length=None)#

Validates that the value of the given field is longer than or equal to the specified length

validate_maxItems(x, fieldname, schema, path, length=None)#

Validates that the value of the given field is shorter than or equal to the specified length

validate_format(x, fieldname, schema, path, format_option=None)#

Validates the format of primitive data types

validate_pattern(x, fieldname, schema, path, pattern=None)#

Validates that the given field, if a string, matches the given regular expression.

validate_uniqueItems(x, fieldname, schema, path, uniqueItems=False)#

Validates that all items in an array instance MUST be unique (contains no two identical values).

validate_enum(x, fieldname, schema, path, options=None)#

Validates that the value of the field is equal to one of the specified option values

validate_disallow(x, fieldname, schema, path, disallow=None)#

Validates that the value of the given field does not match the disallowed type.

validate(data, schema)#

Validates a piece of json data against the provided json-schema.

Exceptions#

class validictory.ValidationError#

Bases: ValueError

validation errors encountered during validation (subclass of ValueError)

class validictory.SchemaError#

Bases: ValueError

errors encountered in processing a schema (subclass of ValueError)