Python Objects#

Schema#

class yankee.base.schema.Schema(*args, flatten=False, prefix=False, **kwargs)[source]#
output_type#

alias of dict

bind(name=None, parent=None, meta=None)[source]#
bind_fields(meta=None)[source]#
get_fields()[source]#
get_model()[source]#
deserialize(obj) Dict[source]#
load_model(obj)[source]#
make_field(t)[source]#
make_dataclass()[source]#
load_batch(objs)[source]#
class yankee.base.schema.PolymorphicSchema(*args, flatten=False, prefix=False, **kwargs)[source]#
bind(name=None, parent=None, meta=None)[source]#
choose_schema(obj)[source]#
deserialize(raw_obj) Dict[source]#
class yankee.base.schema.RegexSchema(*args, **kwargs)[source]#

This schema type allows for using a regex to pull data out of a string, and then treat it like a schema

deserialize(obj)[source]#
bind_fields(meta=None)[source]#
convert_groupdict(obj)[source]#
to_string(elem)[source]#
class yankee.base.schema.ZipSchema(*args, **kwargs)[source]#

This schema type allows fields that produce multiple values to be zipped together into records.

bind(name=None, parent=None, meta=None)[source]#
deserialize(obj) Dict[source]#
load_model(obj)[source]#

Fields#

class yankee.base.fields.Field(*args, default=None, **kwargs)[source]#

The basic field - performs no type casting

output_type = typing.Any#
load(obj)[source]#
class yankee.base.fields.String(*args, formatter=None, null_value=None, **kwargs)[source]#

String Field

Always outputs a string value, or None

Parameters:
  • formatter (Callable) – a callable for formatting the resulting string. Defaults to a newline-preserving whitespace cleaner

  • null_value (str) – a string value to indicate that it should be None. Some data sources use a hyphen or other symbol rather than empty value

output_type#

alias of str

deserialize(elem) Optional[str][source]#
to_string(elem)[source]#
class yankee.base.fields.DateTime(*args, dt_format=None, dt_converter=False, **kwargs)[source]#

DateTime Field

Always outputs a datetime.datetime value. The initial value retrieved should be a string, which is then parsed as an isoformatted date. If that parsing fails, it uses dateutil.parser.parse to attempt to retrieve a datetime.

Parameters:
  • dt_format (str) – a formatting string from datetime.datetime.strptime to use

  • dt_converter (callable) – a custom function to parse a date, overriding the default

output_type#

alias of datetime

parse_date(text: str)[source]#
deserialize(elem) Optional[datetime.datetime][source]#
post_load(obj)[source]#
class yankee.base.fields.Date(*args, dt_format=None, dt_converter=False, **kwargs)[source]#

Date Field

Always outputs a datetime.date value. Uses the same args as DateTime

output_type#

alias of date

deserialize(elem) Optional[datetime.date][source]#
class yankee.base.fields.Boolean(*args, true_value='true', true_func=None, case_sensitive=False, allow_none=True, **kwargs)[source]#

Boolean Field

Always outputs a boolean value (True, or False)

Parameters:
  • true_value (str) – a custom string value that should be considered truthy

  • true_func (Callable) – a custom function that, when executed on the result, should return True or False

  • case_sensitive (str) – if a true_value is provided, whether it should be considered case sensitive

  • allow_none (str) – if the data key doesn’t find a match, and this is true, then it will return None rather than False

output_type#

alias of bool

deserialize(elem) Optional[bool][source]#
class yankee.base.fields.Float(*args, formatter=None, null_value=None, **kwargs)[source]#

Float Field

Always outputs a float value

output_type#

alias of float

deserialize(elem) Optional[float][source]#
class yankee.base.fields.Integer(*args, formatter=None, null_value=None, **kwargs)[source]#

Float Field

Always outputs an integer value. If the value is a float, the result will be the result of calling int on the value.

output_type#

alias of int

deserialize(elem) Optional[int][source]#
class yankee.base.fields.Exists(*args, default=None, **kwargs)[source]#

Exists Field

Outputs true if the data item is present, else false

output_type#

alias of bool

deserialize(elem) bool[source]#
class yankee.base.fields.Const(const, output_type=None, *args, **kwargs)[source]#

Constant Field

Always outputs the provided constant value

Parameters:

const (any) – The constant value to return

deserialize(elem) Any[source]#
class yankee.base.fields.Nested(schema, *args, **kwargs)[source]#
output_type#

alias of dict

bind(name=None, parent=None, meta=None)[source]#
make_accessor(*args, **kwargs)[source]#
load(obj)[source]#
class yankee.base.fields.List(item_schema, data_key=None, **kwargs)[source]#
output_type#

alias of list

bind(name=None, schema=None, meta=None)[source]#
load(obj)[source]#
class yankee.base.fields.Dictionary(data_key, key: Field, value: Field, **kwargs)[source]#
output_type#

Converts a list of items into a dictionary based on the key and value fields passed to it.

alias of dict

load(obj)[source]#
class yankee.base.fields.DelimitedString(item_schema, data_key=None, delimeter=',', **kwargs)[source]#
output_type#

alias of list

bind(name=None, schema=None, meta=None)[source]#
deserialize(obj)[source]#
class yankee.base.fields.Combine(*args, flatten=False, prefix=False, **kwargs)[source]#

Can have fields like a schema that are then passed as an object to a combine function that transforms it to a single string value

output_type#

alias of str

bind(name=None, parent=None, meta=None)[source]#
load(obj)[source]#
combine_func(obj)[source]#
get_model()[source]#
class yankee.base.fields.Alternative(*args, flatten=False, prefix=False, **kwargs)[source]#

There may be a piece of data that has different names in different contexts. This has fields like a schema, then passes as a value the first non-empty or non-null result

deserialize(et_elem)[source]#
yankee.base.fields.Str#

alias of String

yankee.base.fields.DT#

alias of DateTime

yankee.base.fields.Bool#

alias of Boolean

yankee.base.fields.Int#

alias of Integer

yankee.base.fields.Alt#

alias of Alternative

yankee.base.fields.Dict#

alias of Dictionary