Schema class

Class definition

class onctuous.schema.Schema(schema, required=False, extra=False)

A validation schema.

The schema is a Python tree-like structure where nodes are pattern matched against corresponding trees of values.

Nodes can be values, in which case a direct comparison is used, types, in which case an isinstance() check is performed, or callables, which will validate and optionally convert the value.

Public API

__init__

Schema.__init__(schema, required=False, extra=False)

Create a new Schema.

Parameters:
  • schema – Validation schema.
  • required – Keys defined in the schema must be in the data.
  • extra – Keys in the data need not have keys in the schema.

__call__

Schema.__call__(data)

Validate data against self.schema. This simply is a shortcut for validate method.

Parameters:data – input data to validate
Returns:validated input
Raise :InvalidList

validate

Schema.validate(path, schema, data)

Validate data against this schema.

Parameters:
  • path – (list) current path in the object, Starts as []
  • schema – schema to validate agains
  • data – input data to validate
Returns:

validated input

Raise :

InvalidList

Project Versions

Table Of Contents

Previous topic

Errors

Next topic

Schema validators and markers

This Page