Basic types

This module introduce the basic schema types.

class pyrs.schema.types.Array(_jsonschema=None, **attrs)[source]

Bases: pyrs.schema.base.Base

Successful validation of an array instance with regards to these two keywords is determined as follows:

if “items” is not present, or its value is an object, validation of the instance always succeeds, regardless of the value of “additional”

if the value of “additional” is boolean value true or an object, validation of the instance always succeeds;

if the value of “additional” is boolean value false and the value of “items” is an array, the instance is valid if its size is less than, or equal to, the size of “items”.

Array specific options:
min_items:
An array instance is valid against “min_items” if its size is greater than, or equal to, the value of this keyword.
max_items:
An array instance is valid against “max_items” if its size is less than, or equal to, the value of this keyword.
unique_items:
If this keyword has boolean value false, the instance validates successfully. If it has boolean value true, the instance validates successfully if all of its elements are unique.
get_jsonschema(context=None)[source]
class pyrs.schema.types.Boolean(_jsonschema=None, **attrs)[source]

Bases: pyrs.schema.base.Base

class pyrs.schema.types.Date(_jsonschema=None, **attrs)[source]

Bases: pyrs.schema.types.String

to_python(value, context=None)[source]
to_raw(value, context=None)[source]
class pyrs.schema.types.DateTime(_jsonschema=None, **attrs)[source]

Bases: pyrs.schema.types.String

to_python(value, context=None)[source]
to_raw(value, context=None)[source]
class pyrs.schema.types.Duration(_jsonschema=None, **attrs)[source]

Bases: pyrs.schema.types.String

to_python(value, context=None)[source]
to_raw(value, context=None)[source]
class pyrs.schema.types.Enum(_jsonschema=None, **attrs)[source]

Bases: pyrs.schema.base.Base

JSON generic enum class

Parameters:enum (list) – list of possible values
get_jsonschema(context=None)[source]

Ensure the generic schema, remove types

Returns:Gives back the schema
Return type:dict
class pyrs.schema.types.Integer(_jsonschema=None, **attrs)[source]

Bases: pyrs.schema.types.Number

Integer specific agruments:
maximum, exclusive_max:
The value of maximum MUST be a number. The value of exclusive_max MUST be a boolean. If “exclusiveMaximum” is present, “maximum” MUST also be present. Successful validation depends on the presence and value of exclusive_max. If it iss is not present, or has boolean value false, then the instance is valid if it is lower than, or equal to, the value of maximum. If exclusive_max has boolean value true, the instance is valid if it is strictly lower than the value of maximum
minimum, exclusive_min:
The value of minimum MUST be a number. The value of exclusive_min MUST be a boolean. If “exclusiveMinimum” is present, “minimum” MUST also be present. Successful validation depends on the presence and value of exclusive_min. If it iss is not present, or has boolean value false, then the instance is valid if it is greater than, or equal to, the value of minimum. If exclusive_min is present and has boolean value true, the instance is valid if it is strictly greater than the value of minimum.
multiple:
The value MUST be an number. This number MUST be strictly greater than 0. A numeric instance is valid against multiple if the result of the division of the instance by this keyword’s value is an integer.
class pyrs.schema.types.Number(_jsonschema=None, **attrs)[source]

Bases: pyrs.schema.base.Base

Number specific agruments:
maximum, exclusive_max:
The value of maximum MUST be a number. The value of exclusive_max MUST be a boolean. If exclusive_max is present, maximum MUST also be present. Successful validation depends on the presence and value of exclusive_max. If it iss is not present, or has boolean value false, then the instance is valid if it is lower than, or equal to, the value of maximum. If exclusive_max has boolean value true, the instance is valid if it is strictly lower than the value of maximum
minimum, exclusive_min:
The value of minimum MUST be a number. The value of exclusive_min MUST be a boolean. If exclusive_min is present, minimum MUST also be present. Successful validation depends on the presence and value of exclusive_min. If it iss is not present, or has boolean value false, then the instance is valid if it is greater than, or equal to, the value of minimum. If exclusive_min is present and has boolean value true, the instance is valid if it is strictly greater than the value of minimum.
multiple:
The value MUST be an number. This number MUST be strictly greater than 0. A numeric instance is valid against multiple if the result of the division of the instance by this keyword’s value is an integer.
get_jsonschema(context=None)[source]
class pyrs.schema.types.Object(extend=None, **attrs)[source]

Bases: pyrs.schema.base.Base

Declarative schema object

Object specific attributes:
additional:
boolean value: enable or disable extra items on the object schema: items which are valid against the schema allowed to extend false by default
min_properties:
An object instance is valid against min_properties if its number of properties is greater than, or equal to, the value.
max_properties:
An object instance is valid against max_properties if its number of properties is less than, or equal to, the value.
pattern:
Should be a dict where the keys are valid regular excpressions and the values are schema instances. The object instance is valid if the extra properties (which are not listed as property) valid against the schema while name is match on the pattern.

Be careful, the pattern sould be explicit as possible, if the pattern match on any normal property the validation should be successful against them as well.

A normal object should looks like the following:

class Translation(types.Object):
    keyword = types.String()
    value = types.String()

    class Attrs:
        additional = False
        patterns = {
            'value_[a-z]{2}': types.String()
        }
extend(properties, context=None)[source]

Extending the exist same with new properties. If you want to extending with an other schema, you should use the other schame properties

fields
get_jsonschema(context=None)[source]
to_python(value, context=None)[source]

Convert the value to a real python object

to_raw(value, context=None)[source]

Convert the value to a JSON compatible value

class pyrs.schema.types.Ref(_jsonschema=None, **attrs)[source]

Bases: pyrs.schema.base.Base

get_jsonschema(context=None)[source]
class pyrs.schema.types.String(_jsonschema=None, **attrs)[source]

Bases: pyrs.schema.base.Base

String specific arguments:
pattern:
The value of this keyword MUST be a string. This string SHOULD be a valid regular expression, according to the ECMA 262 regular expression dialect. A string instance is considered valid if the regular expression matches the instance successfully. Recall: regular expressions are not implicitly anchored.
minlen (int >=0):
The value of this keyword MUST be an integer. This integer MUST be greater than, or equal to, 0. A string instance is valid against this keyword if its length is greater than, or equal to, the value of this keyword.
maxlen (int >=minlen):
The value of this keyword MUST be an integer. This integer MUST be greater than, or equal to, 0. A string instance is valid against this keyword if its length is less than, or equal to, the value of this keyword.
blank (bool):
The value of blank MUST be a boolean. Successful validation depends on presence and value of min_len. If min_len is present and its value is greather than 0 this keyword has no effect. If min_len is not present or its value is 0 the value of min_len will be set to 1.
get_jsonschema(context=None)[source]
class pyrs.schema.types.Time(_jsonschema=None, **attrs)[source]

Bases: pyrs.schema.types.String

to_python(value, context=None)[source]
to_raw(value, context=None)[source]
class pyrs.schema.types.TimeDelta(_jsonschema=None, **attrs)[source]

Bases: pyrs.schema.types.Number

to_python(value, context=None)[source]
to_raw(value, context=None)[source]