pg.typing.create_schema

Accessible via pg.typing.create_schema.

create_schema(fields, name=None, base_schema_list=None, allow_nonconst_keys=False, metadata=None, description=None)[source]
Return type:

pg.Schema

Creates Schema from a list of ``Field``s or equivalences.

Examples

The following code examples are equivalent:

schema = pg.typing.create_schema({
    'a': int,
    'b': (int, 'field b'),
    'c': (pg.typing.Str(regex='.*'), 'field c', dict(meta1=1))
})

schema = pg.typing.create_schema([
    ('a', int),
    ('b', int, 'field b'),
    ('c', pg.typing.Str(regex='.*'), 'field c', dict(meta1=1)),
])

schema = pg.typing.create_schema([
    pg.typing.Field('a', pg.typing.Int()),
    pg.typing.Field('b', pg.typing.Int(), 'field b'),
    pg.typing.Field(
        'c', pg.typing.Str(regex='.*'), 'field c', dict(meta1=1)),
])
Parameters:
  • fields – A dict, a list of field or equivalent values. A Field equivalent value is either a Field object or a tuple of 2 - 4 elements: (<key>, <value>, [description], [metadata]). key can be a KeySpec subclass object or string. value can be a ValueSpec subclass object or equivalent value. (see ValueSpec.from_value method). description is the description of this field. It can be optional when this field overrides the default value of a field defined in parent schema. metadata is an optional field which is a dict of user objects.

  • name – An optional name for the schema.

  • base_schema_list – A list of schema objects as bases.

  • allow_nonconst_keys – Whether to allow non const keys in schema.

  • metadata – Optional dict of user objects as schema-level metadata.

  • description – Optional description of the schema.

Returns:

Schema object.

Raises:

TypeError – If input type is incorrect.