Field

The Field class defines an individual field in a Schema.

class schema.Field(name, field_type, **kwargs)

Field definitions for a schema. A list of fields defines a schema. Minimum arguments to create a field are a name and a type.

name

Field name

Returns:str
Return type:field name
type

Field type

Returns:str
Return type:field type
format

Field format

Returns:str
Return type:field format
required

Field required

Returns:bool
Return type:true if required
constraints

Field constraints

Returns:dict
Return type:dict of field constraints
settings

Field settings

Returns:dict
Return type:settings
validates

Field validates with minimum required keys

Returns:bool
Return type:True for has all keys
set_constraint(constraint, value)

Set field constraints. User-defined constraints will be automatically passed through, as long as the constraints validate.

Raises:
  • KeyError: if constraint is not permitted in this field
  • ValueError: if value is out of range of that permitted by this constraint
set_missing(value)

Set default value for missing values.

Raises:ValueError: if value is out of range of that permitted by this field
set_format(value='default')

Set field format.

Raises:ValueError: if value is not permitted for this field
set_foreign_key(value)

Set foreign_key value.

Raises:TypeError: if value is not a bool
set_all(**kwargs)

Set all keys and values for this field. Note, this also permits updating of existing name, but not type (which would cause a disaster).

Parameters:

kwargs (dict of all the permitted key: value pairs for this field) –

Raises:
  • ValueError: if name contains spaces
  • TypeError: if string terms are not strings