Fields#
Basic Field Types#
There are basic fields to support Python datatypes. A few have unique options that affect how the type casting process works:
- class yankee.base.fields.Field(*args, default=None, **kwargs)[source]#
The basic field - performs no type casting
- 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
- 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.
- class yankee.base.fields.Float(*args, formatter=None, null_value=None, **kwargs)[source]#
Float Field
Always outputs a float value
- 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
- 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
Special Field Types#
There are also a few special types for common use cases
Schema-Like fields#
There are more fields that behave a bit like Schemas, in that they have subfields:
- 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