Schema IO

This module introduce the base classes for reading and writing data based on schema. The preferred way is using reader is writer rather than using the schema itself. It gives more flexibility and more extensibility.

class pyrs.schema.schemaio.JSONFormReader(schema, context=None)[source]

Bases: pyrs.schema.schemaio.JSONReader

read(data)[source]
class pyrs.schema.schemaio.JSONReader(schema, context=None)[source]

Bases: pyrs.schema.schemaio.Reader

read(data)[source]
class pyrs.schema.schemaio.JSONSchemaDictValidator(schema, context=None)[source]

Bases: pyrs.schema.schemaio.JSONSchemaValidator

validate(data)[source]
class pyrs.schema.schemaio.JSONSchemaValidator(schema, context=None)[source]

Bases: pyrs.schema.schemaio.Validator

validate(data)[source]
class pyrs.schema.schemaio.JSONSchemaWriter(context=None)[source]

Bases: pyrs.schema.schemaio.SchemaWriter

extract(schema, context=None)[source]
write(schema, context=None)[source]
class pyrs.schema.schemaio.JSONWriter(schema, context=None)[source]

Bases: pyrs.schema.schemaio.Writer

write(data)[source]
class pyrs.schema.schemaio.Reader(schema, context=None)[source]

Bases: pyrs.schema.schemaio.SchemaIO

Reader abstract class At least the read method should be implemented

sw = Reader(CustomSchema())
data = sw.write(<custom datastructure>)
read(data)[source]

with self.schema select the proper schema and read the data, validate the input and gives back the decoded value

class pyrs.schema.schemaio.SchemaIO(schema, context=None)[source]

Bases: object

The schema IO gives chance to Schema remain independent from the serialisation method. Even the schema provide conversion still just based on primitive values.

class pyrs.schema.schemaio.SchemaWriter(context=None)[source]

Bases: object

Abstract implementation of schema writer. The main purpose of this class to ensure different useage of the schema. Add extra value if it’s necessary which can’t be implemented by the schema itself.

write(schema)[source]
class pyrs.schema.schemaio.Validator(schema, context=None)[source]

Bases: pyrs.schema.schemaio.SchemaIO

Abstract base class of validators.

validate(data)[source]
class pyrs.schema.schemaio.Writer(schema, context=None)[source]

Bases: pyrs.schema.schemaio.SchemaIO

Writer abstract class At least the write method should be implemented

sw = Writer(CustomSchema())
encoded_data = sw.write({'custom': 'value'})
write(data)[source]

With self.schema select the proper schema, encode the given data then gives it back.

pyrs.schema.schemaio.select_json_validator(schema, context=None)[source]