class FieldDescriptor(name)

FieldDescriptor instances serve as field accessors on models.

class ModelOptions(klass, namespace=None, roles=None, export_level=DEFAULT, serialize_when_none=None, fields_order=None)

This class is a container for all model configuration options. Its primary purpose is to create an independent instance of a model’s options for every class.

class Model(raw_data=None, trusted_data=None, deserialize_mapping=None, init=True, partial=True, strict=True, validate=False, app_data=None, **kwargs)

Enclosure for fields and validation. Same pattern deployed by Django models, SQLAlchemy declarative extension and other developer friendly libraries.

  • raw_data (Mapping) – The data to be imported into the model instance.
  • deserialize_mapping (Mapping) – Can be used to provide alternative input names for fields. Values may be strings or lists of strings, keyed by the actual field name.
  • partial (bool) – Allow partial data to validate. Essentially drops the required=True settings from field definitions. Default: True
  • strict (bool) – Complain about unrecognized keys. Default: True

Iterator for the atomic components of a model definition and relevant data that creates a 3-tuple of the field’s name, its type instance and its value.

convert(raw_data, **kw)

Converts the raw data into richer Python constructs according to the fields on the model

Parameters:raw_data – The data to be converted
flatten(role=None, prefix=u'', app_data=None, context=None)

Return data as a pure key-value dictionary, where the values are primitive types (string, bool, int, long).

  • role – Filter output by a specific role
  • prefix – A prefix to use for keynames during flattening.
classmethod get_mock_object(context=None, overrides=None)

Get a mock object.

  • context (dict) –
  • overrides (dict) – overrides for the model
import_data(raw_data, recursive=False, **kwargs)

Converts and imports the raw data into an existing model instance.

Parameters:raw_data – The data to be imported.
validate(partial=False, convert=True, app_data=None, **kwargs)

Validates the state of the model. If the data is invalid, raises a DataError with error messages.

  • partial (bool) – Allow partial data to validate. Essentially drops the required=True settings from field definitions. Default: False
  • convert – Controls whether to perform import conversion before validating. Can be turned off to skip an unnecessary conversion step if all values are known to have the right datatypes (e.g., when validating immediately after the initial import). Default: True
class ModelMeta

Metaclass for Models.


To learn more about how Models are used, visit Using Models