great_expectations.marshmallow__shade.fields

Field classes for various types of data.

Module Contents

Classes

Field(*, default: typing.Any = missing_, missing: typing.Any = missing_, data_key: str = None, attribute: str = None, validate: typing.Union[typing.Callable[[typing.Any], typing.Any], typing.Iterable[typing.Callable[[typing.Any], typing.Any]]] = None, required: bool = False, allow_none: bool = None, load_only: bool = False, dump_only: bool = False, error_messages: typing.Dict[str, str] = None, **metadata)

Basic field from which other fields should extend. It applies no

Raw(*, default: typing.Any = missing_, missing: typing.Any = missing_, data_key: str = None, attribute: str = None, validate: typing.Union[typing.Callable[[typing.Any], typing.Any], typing.Iterable[typing.Callable[[typing.Any], typing.Any]]] = None, required: bool = False, allow_none: bool = None, load_only: bool = False, dump_only: bool = False, error_messages: typing.Dict[str, str] = None, **metadata)

Field that applies no formatting.

Nested(nested: typing.Union[SchemaABC, type, str, typing.Callable[[], SchemaABC]], *, default: typing.Any = missing_, only: types.StrSequenceOrSet = None, exclude: types.StrSequenceOrSet = (), many: bool = False, unknown: str = None, **kwargs)

Allows you to nest a Schema

Pluck(nested: typing.Union[SchemaABC, type, str, typing.Callable[[], SchemaABC]], field_name: str, **kwargs)

Allows you to replace nested data with one of the data’s fields.

List(cls_or_instance: typing.Union[Field, type], **kwargs)

A list field, composed with another Field class or

Tuple(tuple_fields, *args, **kwargs)

A tuple field, composed of a fixed number of other Field classes or

String(*, default: typing.Any = missing_, missing: typing.Any = missing_, data_key: str = None, attribute: str = None, validate: typing.Union[typing.Callable[[typing.Any], typing.Any], typing.Iterable[typing.Callable[[typing.Any], typing.Any]]] = None, required: bool = False, allow_none: bool = None, load_only: bool = False, dump_only: bool = False, error_messages: typing.Dict[str, str] = None, **metadata)

A string field.

UUID(*, default: typing.Any = missing_, missing: typing.Any = missing_, data_key: str = None, attribute: str = None, validate: typing.Union[typing.Callable[[typing.Any], typing.Any], typing.Iterable[typing.Callable[[typing.Any], typing.Any]]] = None, required: bool = False, allow_none: bool = None, load_only: bool = False, dump_only: bool = False, error_messages: typing.Dict[str, str] = None, **metadata)

A UUID field.

Number(*, as_string: bool = False, **kwargs)

Base class for number fields.

Integer(*, strict: bool = False, **kwargs)

An integer field.

Float(*, allow_nan: bool = False, as_string: bool = False, **kwargs)

A double as an IEEE-754 double precision string.

Decimal(places: int = None, rounding: str = None, *, allow_nan: bool = False, as_string: bool = False, **kwargs)

A field that (de)serializes to the Python decimal.Decimal type.

Boolean(*, truthy: typing.Set = None, falsy: typing.Set = None, **kwargs)

A boolean field.

DateTime(format: str = None, **kwargs)

A formatted datetime string.

NaiveDateTime(format: str = None, *, timezone: dt.timezone = None, **kwargs)

A formatted naive datetime string.

AwareDateTime(format: str = None, *, default_timezone: dt.timezone = None, **kwargs)

A formatted aware datetime string.

Time(*, default: typing.Any = missing_, missing: typing.Any = missing_, data_key: str = None, attribute: str = None, validate: typing.Union[typing.Callable[[typing.Any], typing.Any], typing.Iterable[typing.Callable[[typing.Any], typing.Any]]] = None, required: bool = False, allow_none: bool = None, load_only: bool = False, dump_only: bool = False, error_messages: typing.Dict[str, str] = None, **metadata)

ISO8601-formatted time string.

Date(format: str = None, **kwargs)

ISO8601-formatted date string.

TimeDelta(precision: str = SECONDS, **kwargs)

A field that (de)serializes a datetime.timedelta object to an

Mapping(keys: typing.Union[Field, type] = None, values: typing.Union[Field, type] = None, **kwargs)

An abstract class for objects with key-value pairs.

Dict(keys: typing.Union[Field, type] = None, values: typing.Union[Field, type] = None, **kwargs)

A dict field. Supports dicts and dict-like objects. Extends

Url(*, relative: bool = False, schemes: types.StrSequenceOrSet = None, require_tld: bool = True, **kwargs)

A validated URL field. Validation occurs during both serialization and

Email(*args, **kwargs)

A validated email field. Validation occurs during both serialization and

Method(serialize: str = None, deserialize: str = None, **kwargs)

A field that takes the value returned by a Schema method.

Function(serialize: typing.Union[typing.Callable[[typing.Any], typing.Any], typing.Callable[[typing.Any, typing.Dict], typing.Any]] = None, deserialize: typing.Union[typing.Callable[[typing.Any], typing.Any], typing.Callable[[typing.Any, typing.Dict], typing.Any]] = None, **kwargs)

A field that takes the value returned by a function.

Constant(constant: typing.Any, **kwargs)

A field that (de)serializes to a preset constant. If you only want the

class great_expectations.marshmallow__shade.fields.Field(*, default: typing.Any = missing_, missing: typing.Any = missing_, data_key: str = None, attribute: str = None, validate: typing.Union[typing.Callable[[typing.Any], typing.Any], typing.Iterable[typing.Callable[[typing.Any], typing.Any]]] = None, required: bool = False, allow_none: bool = None, load_only: bool = False, dump_only: bool = False, error_messages: typing.Dict[str, str] = None, **metadata)

Bases: great_expectations.marshmallow__shade.base.FieldABC

Basic field from which other fields should extend. It applies no formatting by default, and should only be used in cases where data does not need to be formatted before being serialized or deserialized. On error, the name of the field will be returned.

Parameters
  • default – If set, this value will be used during serialization if the input value is missing. If not set, the field will be excluded from the serialized output if the input value is missing. May be a value or a callable.

  • missing – Default deserialization value for the field if the field is not found in the input data. May be a value or a callable.

  • data_key – The name of the dict key in the external representation, i.e. the input of load and the output of dump. If None, the key will match the name of the field.

  • attribute – The name of the attribute to get the value from when serializing. If None, assumes the attribute has the same name as the field. Note: This should only be used for very specific use cases such as outputting multiple fields for a single attribute. In most cases, you should use data_key instead.

  • validate – Validator or collection of validators that are called during deserialization. Validator takes a field’s input value as its only parameter and returns a boolean. If it returns False, an ValidationError is raised.

  • required – Raise a ValidationError if the field value is not supplied during deserialization.

  • allow_none – Set this to True if None should be considered a valid value during validation/deserialization. If missing=None and allow_none is unset, will default to True. Otherwise, the default is False.

  • load_only – If True skip this field during serialization, otherwise its value will be present in the serialized data.

  • dump_only – If True skip this field during deserialization, otherwise its value will be present in the deserialized object. In the context of an HTTP API, this effectively marks the field as “read-only”.

  • error_messages (dict) – Overrides for Field.default_error_messages.

  • metadata – Extra arguments to be stored as metadata.

Changed in version 2.0.0: Removed error parameter. Use error_messages instead.

Changed in version 2.0.0: Added allow_none parameter, which makes validation/deserialization of None consistent across fields.

Changed in version 2.0.0: Added load_only and dump_only parameters, which allow field skipping during the (de)serialization process.

Changed in version 2.0.0: Added missing parameter, which indicates the value for a field if the field is not found during deserialization.

Changed in version 2.0.0: default value is only used if explicitly set. Otherwise, missing values inputs are excluded from serialized output.

Changed in version 3.0.0b8: Add data_key parameter for the specifying the key in the input and output data. This parameter replaced both load_from and dump_to.

_CHECK_ATTRIBUTE = True
_creation_index = 0
default_error_messages
__repr__(self)

Return repr(self).

__deepcopy__(self, memo)
get_value(self, obj, attr, accessor=None, default=missing_)

Return the value for a given key from an object.

Parameters
  • obj (object) – The object to get the value from.

  • attr (str) – The attribute/key in obj to get the value from.

  • accessor (callable) – A callable used to retrieve the value of attr from the object obj. Defaults to marshmallow.utils.get_value.

_validate(self, value)

Perform validation on value. Raise a ValidationError if validation does not succeed.

make_error(self, key: str, **kwargs)

Helper method to make a ValidationError with an error message from self.error_messages.

fail(self, key: str, **kwargs)

Helper method that raises a ValidationError with an error message from self.error_messages.

Deprecated since version 3.0.0: Use make_error <marshmallow.fields.Field.make_error> instead.

_validate_missing(self, value)

Validate missing values. Raise a ValidationError if value should be considered missing.

serialize(self, attr: str, obj: typing.Any, accessor: typing.Callable[[typing.Any, str, typing.Any], typing.Any] = None, **kwargs)

Pulls the value for the given key from the object, applies the field’s formatting and returns the result.

Parameters
  • attr – The attribute/key to get from the object.

  • obj – The object to access the attribute/key from.

  • accessor – Function used to access values from obj.

  • kwargs – Field-specific keyword arguments.

deserialize(self, value: typing.Any, attr: str = None, data: typing.Mapping[str, typing.Any] = None, **kwargs)

Deserialize value.

Parameters
  • value – The value to deserialize.

  • attr – The attribute/key in data to deserialize.

  • data – The raw input data passed to Schema.load.

  • kwargs – Field-specific keyword arguments.

Raises

ValidationError – If an invalid value is passed or if a required value is missing.

_bind_to_schema(self, field_name, schema)

Update field with values from its parent schema. Called by Schema._bind_field.

Parameters
  • field_name (str) – Field name set in schema.

  • schema (Schema) – Parent schema.

_serialize(self, value: typing.Any, attr: str, obj: typing.Any, **kwargs)

Serializes value to a basic Python datatype. Noop by default. Concrete Field classes should implement this method.

Example:

class TitleCase(Field):
    def _serialize(self, value, attr, obj, **kwargs):
        if not value:
            return ''
        return str(value).title()
Parameters
  • value – The value to be serialized.

  • attr (str) – The attribute or key on the object to be serialized.

  • obj (object) – The object the value was pulled from.

  • kwargs (dict) – Field-specific keyword arguments.

Returns

The serialized value

_deserialize(self, value: typing.Any, attr: typing.Optional[str], data: typing.Optional[typing.Mapping[str, typing.Any]], **kwargs)

Deserialize value. Concrete Field classes should implement this method.

Parameters
  • value – The value to be deserialized.

  • attr – The attribute/key in data to be deserialized.

  • data – The raw input data passed to the Schema.load.

  • kwargs – Field-specific keyword arguments.

Raises

ValidationError – In case of formatting or validation failure.

Returns

The deserialized value.

Changed in version 2.0.0: Added attr and data parameters.

Changed in version 3.0.0: Added **kwargs to signature.

property context(self)

The context dictionary for the parent Schema.

property root(self)

Reference to the Schema that this field belongs to even if it is buried in a container field (e.g. List). Return None for unbound fields.

class great_expectations.marshmallow__shade.fields.Raw(*, default: typing.Any = missing_, missing: typing.Any = missing_, data_key: str = None, attribute: str = None, validate: typing.Union[typing.Callable[[typing.Any], typing.Any], typing.Iterable[typing.Callable[[typing.Any], typing.Any]]] = None, required: bool = False, allow_none: bool = None, load_only: bool = False, dump_only: bool = False, error_messages: typing.Dict[str, str] = None, **metadata)

Bases: great_expectations.marshmallow__shade.fields.Field

Field that applies no formatting.

class great_expectations.marshmallow__shade.fields.Nested(nested: typing.Union[SchemaABC, type, str, typing.Callable[[], SchemaABC]], *, default: typing.Any = missing_, only: types.StrSequenceOrSet = None, exclude: types.StrSequenceOrSet = (), many: bool = False, unknown: str = None, **kwargs)

Bases: great_expectations.marshmallow__shade.fields.Field

Allows you to nest a Schema inside a field.

Examples:

class ChildSchema(Schema):
    id = fields.Str()
    name = fields.Str()
    # Use lambda functions when you need two-way nesting or self-nesting
    parent = fields.Nested(lambda: ParentSchema(only=("id",)), dump_only=True)
    siblings = fields.List(fields.Nested(lambda: ChildSchema(only=("id", "name"))))

class ParentSchema(Schema):
    id = fields.Str()
    children = fields.List(
        fields.Nested(ChildSchema(only=("id", "parent", "siblings")))
    )
    spouse = fields.Nested(lambda: ParentSchema(only=("id",)))

When passing a Schema <marshmallow.Schema> instance as the first argument, the instance’s exclude, only, and many attributes will be respected.

Therefore, when passing the exclude, only, or many arguments to fields.Nested, you should pass a Schema <marshmallow.Schema> class (not an instance) as the first argument.

# Yes
author = fields.Nested(UserSchema, only=('id', 'name'))

# No
author = fields.Nested(UserSchema(), only=('id', 'name'))
Parameters
  • nestedSchema instance, class, class name (string), or callable that returns a Schema instance.

  • exclude – A list or tuple of fields to exclude.

  • only – A list or tuple of fields to marshal. If None, all fields are marshalled. This parameter takes precedence over exclude.

  • many – Whether the field is a collection of objects.

  • unknown – Whether to exclude, include, or raise an error for unknown fields in the data. Use EXCLUDE, INCLUDE or RAISE.

  • kwargs – The same keyword arguments that Field receives.

default_error_messages
property schema(self)

The nested Schema object.

Changed in version 1.0.0: Renamed from serializer to schema.

_nested_normalized_option(self, option_name: str)
_serialize(self, nested_obj, attr, obj, **kwargs)

Serializes value to a basic Python datatype. Noop by default. Concrete Field classes should implement this method.

Example:

class TitleCase(Field):
    def _serialize(self, value, attr, obj, **kwargs):
        if not value:
            return ''
        return str(value).title()
Parameters
  • value – The value to be serialized.

  • attr (str) – The attribute or key on the object to be serialized.

  • obj (object) – The object the value was pulled from.

  • kwargs (dict) – Field-specific keyword arguments.

Returns

The serialized value

_test_collection(self, value)
_load(self, value, data, partial=None)
_deserialize(self, value, attr, data, partial=None, **kwargs)

Same as Field._deserialize() with additional partial argument.

Parameters

partial (bool|tuple) – For nested schemas, the partial parameter passed to Schema.load.

Changed in version 3.0.0: Add partial parameter.

class great_expectations.marshmallow__shade.fields.Pluck(nested: typing.Union[SchemaABC, type, str, typing.Callable[[], SchemaABC]], field_name: str, **kwargs)

Bases: great_expectations.marshmallow__shade.fields.Nested

Allows you to replace nested data with one of the data’s fields.

Example:

from great_expectations.marshmallow__shade import Schema, fields

class ArtistSchema(Schema):
    id = fields.Int()
    name = fields.Str()

class AlbumSchema(Schema):
    artist = fields.Pluck(ArtistSchema, 'id')


in_data = {'artist': 42}
loaded = AlbumSchema().load(in_data) # => {'artist': {'id': 42}}
dumped = AlbumSchema().dump(loaded)  # => {'artist': 42}
Parameters
  • nested (Schema) – The Schema class or class name (string) to nest, or "self" to nest the Schema within itself.

  • field_name (str) – The key to pluck a value from.

  • kwargs – The same keyword arguments that Nested receives.

property _field_data_key(self)
_serialize(self, nested_obj, attr, obj, **kwargs)

Serializes value to a basic Python datatype. Noop by default. Concrete Field classes should implement this method.

Example:

class TitleCase(Field):
    def _serialize(self, value, attr, obj, **kwargs):
        if not value:
            return ''
        return str(value).title()
Parameters
  • value – The value to be serialized.

  • attr (str) – The attribute or key on the object to be serialized.

  • obj (object) – The object the value was pulled from.

  • kwargs (dict) – Field-specific keyword arguments.

Returns

The serialized value

_deserialize(self, value, attr, data, partial=None, **kwargs)

Same as Field._deserialize() with additional partial argument.

Parameters

partial (bool|tuple) – For nested schemas, the partial parameter passed to Schema.load.

Changed in version 3.0.0: Add partial parameter.

class great_expectations.marshmallow__shade.fields.List(cls_or_instance: typing.Union[Field, type], **kwargs)

Bases: great_expectations.marshmallow__shade.fields.Field

A list field, composed with another Field class or instance.

Example:

numbers = fields.List(fields.Float())
Parameters
  • cls_or_instance – A field class or instance.

  • kwargs – The same keyword arguments that Field receives.

Changed in version 2.0.0: The allow_none parameter now applies to deserialization and has the same semantics as the other fields.

Changed in version 3.0.0rc9: Does not serialize scalar values to single-item lists.

default_error_messages
_bind_to_schema(self, field_name, schema)

Update field with values from its parent schema. Called by Schema._bind_field.

Parameters
  • field_name (str) – Field name set in schema.

  • schema (Schema) – Parent schema.

_serialize(self, value, attr, obj, **kwargs)

Serializes value to a basic Python datatype. Noop by default. Concrete Field classes should implement this method.

Example:

class TitleCase(Field):
    def _serialize(self, value, attr, obj, **kwargs):
        if not value:
            return ''
        return str(value).title()
Parameters
  • value – The value to be serialized.

  • attr (str) – The attribute or key on the object to be serialized.

  • obj (object) – The object the value was pulled from.

  • kwargs (dict) – Field-specific keyword arguments.

Returns

The serialized value

_deserialize(self, value, attr, data, **kwargs)

Deserialize value. Concrete Field classes should implement this method.

Parameters
  • value – The value to be deserialized.

  • attr – The attribute/key in data to be deserialized.

  • data – The raw input data passed to the Schema.load.

  • kwargs – Field-specific keyword arguments.

Raises

ValidationError – In case of formatting or validation failure.

Returns

The deserialized value.

Changed in version 2.0.0: Added attr and data parameters.

Changed in version 3.0.0: Added **kwargs to signature.

class great_expectations.marshmallow__shade.fields.Tuple(tuple_fields, *args, **kwargs)

Bases: great_expectations.marshmallow__shade.fields.Field

A tuple field, composed of a fixed number of other Field classes or instances

Example:

row = Tuple((fields.String(), fields.Integer(), fields.Float()))

Note

Because of the structured nature of collections.namedtuple and typing.NamedTuple, using a Schema within a Nested field for them is more appropriate than using a Tuple field.

Parameters
  • tuple_fields (Iterable[Field]) – An iterable of field classes or instances.

  • kwargs – The same keyword arguments that Field receives.

New in version 3.0.0rc4.

default_error_messages
_bind_to_schema(self, field_name, schema)

Update field with values from its parent schema. Called by Schema._bind_field.

Parameters
  • field_name (str) – Field name set in schema.

  • schema (Schema) – Parent schema.

_serialize(self, value, attr, obj, **kwargs)

Serializes value to a basic Python datatype. Noop by default. Concrete Field classes should implement this method.

Example:

class TitleCase(Field):
    def _serialize(self, value, attr, obj, **kwargs):
        if not value:
            return ''
        return str(value).title()
Parameters
  • value – The value to be serialized.

  • attr (str) – The attribute or key on the object to be serialized.

  • obj (object) – The object the value was pulled from.

  • kwargs (dict) – Field-specific keyword arguments.

Returns

The serialized value

_deserialize(self, value, attr, data, **kwargs)

Deserialize value. Concrete Field classes should implement this method.

Parameters
  • value – The value to be deserialized.

  • attr – The attribute/key in data to be deserialized.

  • data – The raw input data passed to the Schema.load.

  • kwargs – Field-specific keyword arguments.

Raises

ValidationError – In case of formatting or validation failure.

Returns

The deserialized value.

Changed in version 2.0.0: Added attr and data parameters.

Changed in version 3.0.0: Added **kwargs to signature.

class great_expectations.marshmallow__shade.fields.String(*, default: typing.Any = missing_, missing: typing.Any = missing_, data_key: str = None, attribute: str = None, validate: typing.Union[typing.Callable[[typing.Any], typing.Any], typing.Iterable[typing.Callable[[typing.Any], typing.Any]]] = None, required: bool = False, allow_none: bool = None, load_only: bool = False, dump_only: bool = False, error_messages: typing.Dict[str, str] = None, **metadata)

Bases: great_expectations.marshmallow__shade.fields.Field

A string field.

Parameters

kwargs – The same keyword arguments that Field receives.

default_error_messages
_serialize(self, value, attr, obj, **kwargs)

Serializes value to a basic Python datatype. Noop by default. Concrete Field classes should implement this method.

Example:

class TitleCase(Field):
    def _serialize(self, value, attr, obj, **kwargs):
        if not value:
            return ''
        return str(value).title()
Parameters
  • value – The value to be serialized.

  • attr (str) – The attribute or key on the object to be serialized.

  • obj (object) – The object the value was pulled from.

  • kwargs (dict) – Field-specific keyword arguments.

Returns

The serialized value

_deserialize(self, value, attr, data, **kwargs)

Deserialize value. Concrete Field classes should implement this method.

Parameters
  • value – The value to be deserialized.

  • attr – The attribute/key in data to be deserialized.

  • data – The raw input data passed to the Schema.load.

  • kwargs – Field-specific keyword arguments.

Raises

ValidationError – In case of formatting or validation failure.

Returns

The deserialized value.

Changed in version 2.0.0: Added attr and data parameters.

Changed in version 3.0.0: Added **kwargs to signature.

class great_expectations.marshmallow__shade.fields.UUID(*, default: typing.Any = missing_, missing: typing.Any = missing_, data_key: str = None, attribute: str = None, validate: typing.Union[typing.Callable[[typing.Any], typing.Any], typing.Iterable[typing.Callable[[typing.Any], typing.Any]]] = None, required: bool = False, allow_none: bool = None, load_only: bool = False, dump_only: bool = False, error_messages: typing.Dict[str, str] = None, **metadata)

Bases: great_expectations.marshmallow__shade.fields.String

A UUID field.

default_error_messages
_validated(self, value)

Format the value or raise a ValidationError if an error occurs.

_deserialize(self, value, attr, data, **kwargs)

Deserialize value. Concrete Field classes should implement this method.

Parameters
  • value – The value to be deserialized.

  • attr – The attribute/key in data to be deserialized.

  • data – The raw input data passed to the Schema.load.

  • kwargs – Field-specific keyword arguments.

Raises

ValidationError – In case of formatting or validation failure.

Returns

The deserialized value.

Changed in version 2.0.0: Added attr and data parameters.

Changed in version 3.0.0: Added **kwargs to signature.

class great_expectations.marshmallow__shade.fields.Number(*, as_string: bool = False, **kwargs)

Bases: great_expectations.marshmallow__shade.fields.Field

Base class for number fields.

Parameters
  • as_string (bool) – If True, format the serialized value as a string.

  • kwargs – The same keyword arguments that Field receives.

num_type :typing.Type
default_error_messages
_format_num(self, value)

Return the number value for value, given this field’s num_type.

_validated(self, value)

Format the value or raise a ValidationError if an error occurs.

_to_string(self, value)
_serialize(self, value, attr, obj, **kwargs)

Return a string if self.as_string=True, otherwise return this field’s num_type.

_deserialize(self, value, attr, data, **kwargs)

Deserialize value. Concrete Field classes should implement this method.

Parameters
  • value – The value to be deserialized.

  • attr – The attribute/key in data to be deserialized.

  • data – The raw input data passed to the Schema.load.

  • kwargs – Field-specific keyword arguments.

Raises

ValidationError – In case of formatting or validation failure.

Returns

The deserialized value.

Changed in version 2.0.0: Added attr and data parameters.

Changed in version 3.0.0: Added **kwargs to signature.

class great_expectations.marshmallow__shade.fields.Integer(*, strict: bool = False, **kwargs)

Bases: great_expectations.marshmallow__shade.fields.Number

An integer field.

Parameters
  • strict – If True, only integer types are valid. Otherwise, any value castable to int is valid.

  • kwargs – The same keyword arguments that Number receives.

num_type
default_error_messages
_validated(self, value)

Format the value or raise a ValidationError if an error occurs.

class great_expectations.marshmallow__shade.fields.Float(*, allow_nan: bool = False, as_string: bool = False, **kwargs)

Bases: great_expectations.marshmallow__shade.fields.Number

A double as an IEEE-754 double precision string.

Parameters
  • allow_nan (bool) – If True, NaN, Infinity and -Infinity are allowed, even though they are illegal according to the JSON specification.

  • as_string (bool) – If True, format the value as a string.

  • kwargs – The same keyword arguments that Number receives.

num_type
default_error_messages
_validated(self, value)

Format the value or raise a ValidationError if an error occurs.

class great_expectations.marshmallow__shade.fields.Decimal(places: int = None, rounding: str = None, *, allow_nan: bool = False, as_string: bool = False, **kwargs)

Bases: great_expectations.marshmallow__shade.fields.Number

A field that (de)serializes to the Python decimal.Decimal type. It’s safe to use when dealing with money values, percentages, ratios or other numbers where precision is critical.

Warning

This field serializes to a decimal.Decimal object by default. If you need to render your data as JSON, keep in mind that the json module from the standard library does not encode decimal.Decimal. Therefore, you must use a JSON library that can handle decimals, such as simplejson, or serialize to a string by passing as_string=True.

Warning

If a JSON float value is passed to this field for deserialization it will first be cast to its corresponding string value before being deserialized to a decimal.Decimal object. The default __str__ implementation of the built-in Python float type may apply a destructive transformation upon its input data and therefore cannot be relied upon to preserve precision. To avoid this, you can instead pass a JSON string to be deserialized directly.

Parameters
  • places – How many decimal places to quantize the value. If None, does not quantize the value.

  • rounding – How to round the value during quantize, for example decimal.ROUND_UP. If None, uses the rounding value from the current thread’s context.

  • allow_nan – If True, NaN, Infinity and -Infinity are allowed, even though they are illegal according to the JSON specification.

  • as_string – If True, serialize to a string instead of a Python decimal.Decimal type.

  • kwargs – The same keyword arguments that Number receives.

New in version 1.2.0.

num_type
default_error_messages
_format_num(self, value)

Return the number value for value, given this field’s num_type.

_validated(self, value)

Format the value or raise a ValidationError if an error occurs.

_to_string(self, value)
class great_expectations.marshmallow__shade.fields.Boolean(*, truthy: typing.Set = None, falsy: typing.Set = None, **kwargs)

Bases: great_expectations.marshmallow__shade.fields.Field

A boolean field.

Parameters
  • truthy – Values that will (de)serialize to True. If an empty set, any non-falsy value will deserialize to True. If None, marshmallow.fields.Boolean.truthy will be used.

  • falsy – Values that will (de)serialize to False. If None, marshmallow.fields.Boolean.falsy will be used.

  • kwargs – The same keyword arguments that Field receives.

truthy
falsy
default_error_messages
_serialize(self, value, attr, obj, **kwargs)

Serializes value to a basic Python datatype. Noop by default. Concrete Field classes should implement this method.

Example:

class TitleCase(Field):
    def _serialize(self, value, attr, obj, **kwargs):
        if not value:
            return ''
        return str(value).title()
Parameters
  • value – The value to be serialized.

  • attr (str) – The attribute or key on the object to be serialized.

  • obj (object) – The object the value was pulled from.

  • kwargs (dict) – Field-specific keyword arguments.

Returns

The serialized value

_deserialize(self, value, attr, data, **kwargs)

Deserialize value. Concrete Field classes should implement this method.

Parameters
  • value – The value to be deserialized.

  • attr – The attribute/key in data to be deserialized.

  • data – The raw input data passed to the Schema.load.

  • kwargs – Field-specific keyword arguments.

Raises

ValidationError – In case of formatting or validation failure.

Returns

The deserialized value.

Changed in version 2.0.0: Added attr and data parameters.

Changed in version 3.0.0: Added **kwargs to signature.

class great_expectations.marshmallow__shade.fields.DateTime(format: str = None, **kwargs)

Bases: great_expectations.marshmallow__shade.fields.Field

A formatted datetime string.

Example: '2014-12-22T03:12:58.019077+00:00'

Parameters
  • format – Either "rfc" (for RFC822), "iso" (for ISO8601), or a date format string. If None, defaults to “iso”.

  • kwargs – The same keyword arguments that Field receives.

Changed in version 3.0.0rc9: Does not modify timezone information on (de)serialization.

SERIALIZATION_FUNCS :typing.Dict[str, typing.Callable[[typing.Any], str]]
DESERIALIZATION_FUNCS :typing.Dict[str, typing.Callable[[str], typing.Any]]
DEFAULT_FORMAT = iso
OBJ_TYPE = datetime
SCHEMA_OPTS_VAR_NAME = datetimeformat
default_error_messages
_bind_to_schema(self, field_name, schema)

Update field with values from its parent schema. Called by Schema._bind_field.

Parameters
  • field_name (str) – Field name set in schema.

  • schema (Schema) – Parent schema.

_serialize(self, value, attr, obj, **kwargs)

Serializes value to a basic Python datatype. Noop by default. Concrete Field classes should implement this method.

Example:

class TitleCase(Field):
    def _serialize(self, value, attr, obj, **kwargs):
        if not value:
            return ''
        return str(value).title()
Parameters
  • value – The value to be serialized.

  • attr (str) – The attribute or key on the object to be serialized.

  • obj (object) – The object the value was pulled from.

  • kwargs (dict) – Field-specific keyword arguments.

Returns

The serialized value

_deserialize(self, value, attr, data, **kwargs)

Deserialize value. Concrete Field classes should implement this method.

Parameters
  • value – The value to be deserialized.

  • attr – The attribute/key in data to be deserialized.

  • data – The raw input data passed to the Schema.load.

  • kwargs – Field-specific keyword arguments.

Raises

ValidationError – In case of formatting or validation failure.

Returns

The deserialized value.

Changed in version 2.0.0: Added attr and data parameters.

Changed in version 3.0.0: Added **kwargs to signature.

static _make_object_from_format(value, data_format)
class great_expectations.marshmallow__shade.fields.NaiveDateTime(format: str = None, *, timezone: dt.timezone = None, **kwargs)

Bases: great_expectations.marshmallow__shade.fields.DateTime

A formatted naive datetime string.

Parameters
  • format – See DateTime.

  • timezone – Used on deserialization. If None, aware datetimes are rejected. If not None, aware datetimes are converted to this timezone before their timezone information is removed.

  • kwargs – The same keyword arguments that Field receives.

New in version 3.0.0rc9.

AWARENESS = naive
_deserialize(self, value, attr, data, **kwargs)

Deserialize value. Concrete Field classes should implement this method.

Parameters
  • value – The value to be deserialized.

  • attr – The attribute/key in data to be deserialized.

  • data – The raw input data passed to the Schema.load.

  • kwargs – Field-specific keyword arguments.

Raises

ValidationError – In case of formatting or validation failure.

Returns

The deserialized value.

Changed in version 2.0.0: Added attr and data parameters.

Changed in version 3.0.0: Added **kwargs to signature.

class great_expectations.marshmallow__shade.fields.AwareDateTime(format: str = None, *, default_timezone: dt.timezone = None, **kwargs)

Bases: great_expectations.marshmallow__shade.fields.DateTime

A formatted aware datetime string.

Parameters
  • format – See DateTime.

  • default_timezone – Used on deserialization. If None, naive datetimes are rejected. If not None, naive datetimes are set this timezone.

  • kwargs – The same keyword arguments that Field receives.

New in version 3.0.0rc9.

AWARENESS = aware
_deserialize(self, value, attr, data, **kwargs)

Deserialize value. Concrete Field classes should implement this method.

Parameters
  • value – The value to be deserialized.

  • attr – The attribute/key in data to be deserialized.

  • data – The raw input data passed to the Schema.load.

  • kwargs – Field-specific keyword arguments.

Raises

ValidationError – In case of formatting or validation failure.

Returns

The deserialized value.

Changed in version 2.0.0: Added attr and data parameters.

Changed in version 3.0.0: Added **kwargs to signature.

class great_expectations.marshmallow__shade.fields.Time(*, default: typing.Any = missing_, missing: typing.Any = missing_, data_key: str = None, attribute: str = None, validate: typing.Union[typing.Callable[[typing.Any], typing.Any], typing.Iterable[typing.Callable[[typing.Any], typing.Any]]] = None, required: bool = False, allow_none: bool = None, load_only: bool = False, dump_only: bool = False, error_messages: typing.Dict[str, str] = None, **metadata)

Bases: great_expectations.marshmallow__shade.fields.Field

ISO8601-formatted time string.

Parameters

kwargs – The same keyword arguments that Field receives.

default_error_messages
_serialize(self, value, attr, obj, **kwargs)

Serializes value to a basic Python datatype. Noop by default. Concrete Field classes should implement this method.

Example:

class TitleCase(Field):
    def _serialize(self, value, attr, obj, **kwargs):
        if not value:
            return ''
        return str(value).title()
Parameters
  • value – The value to be serialized.

  • attr (str) – The attribute or key on the object to be serialized.

  • obj (object) – The object the value was pulled from.

  • kwargs (dict) – Field-specific keyword arguments.

Returns

The serialized value

_deserialize(self, value, attr, data, **kwargs)

Deserialize an ISO8601-formatted time to a datetime.time object.

class great_expectations.marshmallow__shade.fields.Date(format: str = None, **kwargs)

Bases: great_expectations.marshmallow__shade.fields.DateTime

ISO8601-formatted date string.

Parameters
  • format – Either "iso" (for ISO8601) or a date format string. If None, defaults to “iso”.

  • kwargs – The same keyword arguments that Field receives.

default_error_messages
SERIALIZATION_FUNCS
DESERIALIZATION_FUNCS
DEFAULT_FORMAT = iso
OBJ_TYPE = date
SCHEMA_OPTS_VAR_NAME = dateformat
static _make_object_from_format(value, data_format)
class great_expectations.marshmallow__shade.fields.TimeDelta(precision: str = SECONDS, **kwargs)

Bases: great_expectations.marshmallow__shade.fields.Field

A field that (de)serializes a datetime.timedelta object to an integer and vice versa. The integer can represent the number of days, seconds or microseconds.

Parameters
  • precision – Influences how the integer is interpreted during (de)serialization. Must be ‘days’, ‘seconds’, ‘microseconds’, ‘milliseconds’, ‘minutes’, ‘hours’ or ‘weeks’.

  • kwargs – The same keyword arguments that Field receives.

Changed in version 2.0.0: Always serializes to an integer value to avoid rounding errors. Add precision parameter.

DAYS = days
SECONDS = seconds
MICROSECONDS = microseconds
MILLISECONDS = milliseconds
MINUTES = minutes
HOURS = hours
WEEKS = weeks
default_error_messages
_serialize(self, value, attr, obj, **kwargs)

Serializes value to a basic Python datatype. Noop by default. Concrete Field classes should implement this method.

Example:

class TitleCase(Field):
    def _serialize(self, value, attr, obj, **kwargs):
        if not value:
            return ''
        return str(value).title()
Parameters
  • value – The value to be serialized.

  • attr (str) – The attribute or key on the object to be serialized.

  • obj (object) – The object the value was pulled from.

  • kwargs (dict) – Field-specific keyword arguments.

Returns

The serialized value

_deserialize(self, value, attr, data, **kwargs)

Deserialize value. Concrete Field classes should implement this method.

Parameters
  • value – The value to be deserialized.

  • attr – The attribute/key in data to be deserialized.

  • data – The raw input data passed to the Schema.load.

  • kwargs – Field-specific keyword arguments.

Raises

ValidationError – In case of formatting or validation failure.

Returns

The deserialized value.

Changed in version 2.0.0: Added attr and data parameters.

Changed in version 3.0.0: Added **kwargs to signature.

class great_expectations.marshmallow__shade.fields.Mapping(keys: typing.Union[Field, type] = None, values: typing.Union[Field, type] = None, **kwargs)

Bases: great_expectations.marshmallow__shade.fields.Field

An abstract class for objects with key-value pairs.

Parameters
  • keys – A field class or instance for dict keys.

  • values – A field class or instance for dict values.

  • kwargs – The same keyword arguments that Field receives.

Note

When the structure of nested data is not known, you may omit the keys and values arguments to prevent content validation.

New in version 3.0.0rc4.

mapping_type
default_error_messages
_bind_to_schema(self, field_name, schema)

Update field with values from its parent schema. Called by Schema._bind_field.

Parameters
  • field_name (str) – Field name set in schema.

  • schema (Schema) – Parent schema.

_serialize(self, value, attr, obj, **kwargs)

Serializes value to a basic Python datatype. Noop by default. Concrete Field classes should implement this method.

Example:

class TitleCase(Field):
    def _serialize(self, value, attr, obj, **kwargs):
        if not value:
            return ''
        return str(value).title()
Parameters
  • value – The value to be serialized.

  • attr (str) – The attribute or key on the object to be serialized.

  • obj (object) – The object the value was pulled from.

  • kwargs (dict) – Field-specific keyword arguments.

Returns

The serialized value

_deserialize(self, value, attr, data, **kwargs)

Deserialize value. Concrete Field classes should implement this method.

Parameters
  • value – The value to be deserialized.

  • attr – The attribute/key in data to be deserialized.

  • data – The raw input data passed to the Schema.load.

  • kwargs – Field-specific keyword arguments.

Raises

ValidationError – In case of formatting or validation failure.

Returns

The deserialized value.

Changed in version 2.0.0: Added attr and data parameters.

Changed in version 3.0.0: Added **kwargs to signature.

class great_expectations.marshmallow__shade.fields.Dict(keys: typing.Union[Field, type] = None, values: typing.Union[Field, type] = None, **kwargs)

Bases: great_expectations.marshmallow__shade.fields.Mapping

A dict field. Supports dicts and dict-like objects. Extends Mapping with dict as the mapping_type.

Example:

numbers = fields.Dict(keys=fields.Str(), values=fields.Float())
Parameters

kwargs – The same keyword arguments that Mapping receives.

New in version 2.1.0.

mapping_type
class great_expectations.marshmallow__shade.fields.Url(*, relative: bool = False, schemes: types.StrSequenceOrSet = None, require_tld: bool = True, **kwargs)

Bases: great_expectations.marshmallow__shade.fields.String

A validated URL field. Validation occurs during both serialization and deserialization.

Parameters
  • default – Default value for the field if the attribute is not set.

  • relative – Whether to allow relative URLs.

  • require_tld – Whether to reject non-FQDN hostnames.

  • schemes – Valid schemes. By default, http, https, ftp, and ftps are allowed.

  • kwargs – The same keyword arguments that String receives.

default_error_messages
class great_expectations.marshmallow__shade.fields.Email(*args, **kwargs)

Bases: great_expectations.marshmallow__shade.fields.String

A validated email field. Validation occurs during both serialization and deserialization.

Parameters
  • args – The same positional arguments that String receives.

  • kwargs – The same keyword arguments that String receives.

default_error_messages
class great_expectations.marshmallow__shade.fields.Method(serialize: str = None, deserialize: str = None, **kwargs)

Bases: great_expectations.marshmallow__shade.fields.Field

A field that takes the value returned by a Schema method.

Parameters
  • serialize (str) – The name of the Schema method from which to retrieve the value. The method must take an argument obj (in addition to self) that is the object to be serialized.

  • deserialize (str) – Optional name of the Schema method for deserializing a value The method must take a single argument value, which is the value to deserialize.

Changed in version 2.0.0: Removed optional context parameter on methods. Use self.context instead.

Changed in version 2.3.0: Deprecated method_name parameter in favor of serialize and allow serialize to not be passed at all.

Changed in version 3.0.0: Removed method_name parameter.

_CHECK_ATTRIBUTE = False
_serialize(self, value, attr, obj, **kwargs)

Serializes value to a basic Python datatype. Noop by default. Concrete Field classes should implement this method.

Example:

class TitleCase(Field):
    def _serialize(self, value, attr, obj, **kwargs):
        if not value:
            return ''
        return str(value).title()
Parameters
  • value – The value to be serialized.

  • attr (str) – The attribute or key on the object to be serialized.

  • obj (object) – The object the value was pulled from.

  • kwargs (dict) – Field-specific keyword arguments.

Returns

The serialized value

_deserialize(self, value, attr, data, **kwargs)

Deserialize value. Concrete Field classes should implement this method.

Parameters
  • value – The value to be deserialized.

  • attr – The attribute/key in data to be deserialized.

  • data – The raw input data passed to the Schema.load.

  • kwargs – Field-specific keyword arguments.

Raises

ValidationError – In case of formatting or validation failure.

Returns

The deserialized value.

Changed in version 2.0.0: Added attr and data parameters.

Changed in version 3.0.0: Added **kwargs to signature.

class great_expectations.marshmallow__shade.fields.Function(serialize: typing.Union[typing.Callable[[typing.Any], typing.Any], typing.Callable[[typing.Any, typing.Dict], typing.Any]] = None, deserialize: typing.Union[typing.Callable[[typing.Any], typing.Any], typing.Callable[[typing.Any, typing.Dict], typing.Any]] = None, **kwargs)

Bases: great_expectations.marshmallow__shade.fields.Field

A field that takes the value returned by a function.

Parameters
  • serialize – A callable from which to retrieve the value. The function must take a single argument obj which is the object to be serialized. It can also optionally take a context argument, which is a dictionary of context variables passed to the serializer. If no callable is provided then the `load_only` flag will be set to True.

  • deserialize – A callable from which to retrieve the value. The function must take a single argument value which is the value to be deserialized. It can also optionally take a context argument, which is a dictionary of context variables passed to the deserializer. If no callable is provided then `value` will be passed through unchanged.

Changed in version 2.3.0: Deprecated func parameter in favor of serialize.

Changed in version 3.0.0a1: Removed func parameter.

_CHECK_ATTRIBUTE = False
_serialize(self, value, attr, obj, **kwargs)

Serializes value to a basic Python datatype. Noop by default. Concrete Field classes should implement this method.

Example:

class TitleCase(Field):
    def _serialize(self, value, attr, obj, **kwargs):
        if not value:
            return ''
        return str(value).title()
Parameters
  • value – The value to be serialized.

  • attr (str) – The attribute or key on the object to be serialized.

  • obj (object) – The object the value was pulled from.

  • kwargs (dict) – Field-specific keyword arguments.

Returns

The serialized value

_deserialize(self, value, attr, data, **kwargs)

Deserialize value. Concrete Field classes should implement this method.

Parameters
  • value – The value to be deserialized.

  • attr – The attribute/key in data to be deserialized.

  • data – The raw input data passed to the Schema.load.

  • kwargs – Field-specific keyword arguments.

Raises

ValidationError – In case of formatting or validation failure.

Returns

The deserialized value.

Changed in version 2.0.0: Added attr and data parameters.

Changed in version 3.0.0: Added **kwargs to signature.

_call_or_raise(self, func, value, attr)
class great_expectations.marshmallow__shade.fields.Constant(constant: typing.Any, **kwargs)

Bases: great_expectations.marshmallow__shade.fields.Field

A field that (de)serializes to a preset constant. If you only want the constant added for serialization or deserialization, you should use dump_only=True or load_only=True respectively.

Parameters

constant – The constant to return for the field attribute.

New in version 2.0.0.

_CHECK_ATTRIBUTE = False
_serialize(self, value, *args, **kwargs)

Serializes value to a basic Python datatype. Noop by default. Concrete Field classes should implement this method.

Example:

class TitleCase(Field):
    def _serialize(self, value, attr, obj, **kwargs):
        if not value:
            return ''
        return str(value).title()
Parameters
  • value – The value to be serialized.

  • attr (str) – The attribute or key on the object to be serialized.

  • obj (object) – The object the value was pulled from.

  • kwargs (dict) – Field-specific keyword arguments.

Returns

The serialized value

_deserialize(self, value, *args, **kwargs)

Deserialize value. Concrete Field classes should implement this method.

Parameters
  • value – The value to be deserialized.

  • attr – The attribute/key in data to be deserialized.

  • data – The raw input data passed to the Schema.load.

  • kwargs – Field-specific keyword arguments.

Raises

ValidationError – In case of formatting or validation failure.

Returns

The deserialized value.

Changed in version 2.0.0: Added attr and data parameters.

Changed in version 3.0.0: Added **kwargs to signature.

great_expectations.marshmallow__shade.fields.URL
great_expectations.marshmallow__shade.fields.Str
great_expectations.marshmallow__shade.fields.Bool
great_expectations.marshmallow__shade.fields.Int