Transforms

whitelist(*field_list)

Returns a function that operates as a whitelist for the provided list of fields.

A whitelist is a list of fields explicitly named that are allowed.

import_loop(schema, mutable, raw_data=None, field_converter=None, trusted_data=None, mapping=None, partial=False, strict=False, init_values=False, apply_defaults=False, convert=True, validate=False, new=False, oo=False, recursive=False, app_data=None, context=None)

The import loop is designed to take untrusted data and convert it into the native types, as described in schema. It does this by calling field_converter on every field.

Errors are aggregated and returned by throwing a ModelConversionError.

Parameters:
  • schema – The Schema to use as source for validation.
  • mutable – A mapping or instance that can be changed during validation by Schema functions.
  • raw_data – A mapping to be converted into types according to schema.
  • field_converter – This function is applied to every field found in instance_or_dict.
  • trusted_data – A dict-like structure that may contain already validated data.
  • partial – Allow partial data to validate; useful for PATCH requests. Essentially drops the required=True arguments from field definitions. Default: False
  • strict – Complain about unrecognized keys. Default: False
  • apply_defaults – Whether to set fields to their default values when not present in input data.
  • app_data – An arbitrary container for application-specific data that needs to be available during the conversion.
  • context – A Context object that encapsulates configuration options and app_data. The context object is created upon the initial invocation of import_loop and is then propagated through the entire process.
wholelist(*field_list)

Returns a function that evicts nothing. Exists mainly to be an explicit allowance of all fields instead of a using an empty blacklist.

blacklist(*field_list)

Returns a function that operates as a blacklist for the provided list of fields.

A blacklist is a list of fields explicitly named that are not allowed.

export_loop(schema, instance_or_dict, field_converter=None, role=None, raise_error_on_role=True, export_level=None, app_data=None, context=None)

The export_loop function is intended to be a general loop definition that can be used for any form of data shaping, such as application of roles or how a field is transformed.

Parameters:
  • schema – The Schema to use as source for validation.
  • instance_or_dict – The structure where fields from schema are mapped to values. The only expectation for this structure is that it implements a dict interface.
  • field_converter – This function is applied to every field found in instance_or_dict.
  • role – The role used to determine if fields should be left out of the transformation.
  • raise_error_on_role – This parameter enforces strict behavior which requires substructures to have the same role definition as their parent structures.
  • app_data – An arbitrary container for application-specific data that needs to be available during the conversion.
  • context – A Context object that encapsulates configuration options and app_data. The context object is created upon the initial invocation of import_loop and is then propagated through the entire process.

Usage

To learn more about how Transforms are used, visit Using Importing and Using Exporting