Fields

class springfield.fields.AdaptableTypeField(default=Empty, doc=None, *args, **kwargs)[source]

A Field that has a specific type and can be adapted to another type.

adapt(value)[source]

Convert the value to the self.type for this Field

classmethod register_adapter(from_cls, func)[source]

Register a function that can handle adapting from from_cls for this field.

TODO This may be a bad idea, re-evaluate how to register adapters.

type = None

The value type this Field expects

class springfield.fields.BooleanField(default=Empty, doc=None, *args, **kwargs)[source]

A Field that contains a bool.

adapt(value)[source]

Adapt value to a bool.

Parameters:value

A boolean-like value.

A float, int, or long will be converted to:

  • True if equal to 1
  • False if equal to 0

String values will be converted to (case-insensitive):

  • True if equal to “yes”, “true”, “1”, or “on”
  • False if equal to “no”, “false”, “0”, or “off”
type

alias of bool

class springfield.fields.CollectionField(field, *args, **kwargs)[source]

A Field that can contain an ordered list of values matching a specific Field type.

adapt(value)[source]

Adapt all values of an iterable to the CollectionField‘s field type.

field = None

The Field this collection contains

flatten(value)[source]

Convert all values of an iterable to the CollectionField‘s field type’s native Python type.

jsonify(value)[source]

Convert all values of an iterable to the CollectionField‘s field type’s JSON type.

class springfield.fields.DateTimeField(default=Empty, doc=None, *args, **kwargs)[source]

Field whose value is a Python datetime.datetime

adapt(value)[source]

Adapt value to a datetime.datetime instance.

Parameters:value

A date-like value. RFC3339 formatted date-strings are supported.

If dateutil is installed, dateutil.parser.parse is used which supports many date formats.

jsonify(value)[source]

Get the date as a RFC3339 date-string

type

alias of datetime

class springfield.fields.EmailField(default=Empty, doc=None, *args, **kwargs)[source]

Field with an email value

class springfield.fields.EntityField(entity, *args, **kwargs)[source]

Field that can contain an Entity

flatten(value)[source]

Convert an Entity to a dict containing native Python types.

jsonify(value)[source]

Convert an Entity into a JSON object

class springfield.fields.Field(default=Empty, doc=None, *args, **kwargs)[source]

A field

adapt(value)[source]

Convert the value from the input type to the expected type if needed.

Returns:The adapted value
flatten(value)[source]

Get the value as a basic Python type

Parameters:value – An Entity‘s value for this Field
init(cls)[source]

Initialize the field for its owner Entity class. Any specialization that needs to be done based on the Entity class itself should be done here.

Parameters:cls – An Entity class.
jsonify(value)[source]

Get the value as a suitable JSON type

Parameters:value – An Entity‘s value for this Field
make_descriptor(name)[source]

Create a descriptor for this Field to attach to an Entity.

class springfield.fields.FieldDescriptor(name, field)[source]

A descriptor that handles setting and getting Field values on an Entity.

class springfield.fields.FloatField(default=Empty, doc=None, *args, **kwargs)[source]

A Field that contains a float.

adapt(value)[source]

Adapt value to a float.

Parameters:value

Can be an int, float, long, or a str or unicode that looks like a float.

long values will remain `long`s.

type

alias of float

class springfield.fields.IdField(default=Empty, doc=None, *args, **kwargs)[source]

A Field that is used as the primary identifier for an Entity

TODO This should accept another Field type to contain the ID

class springfield.fields.IntField(default=Empty, doc=None, *args, **kwargs)[source]

A Field that contains an int.

adapt(value)[source]

Adapt value to an int.

Parameters:value

Can be an int, float, long, or a str or unicode that looks like an int.

float or long values must represent an integer, i.e. no decimal places.

type

alias of int

class springfield.fields.SlugField(default=Empty, doc=None, *args, **kwargs)[source]

Field whose value is a slugified string.

A slug is a string converted to lowercase with whitespace replace with a “-” and non-ascii chars converted to their ascii equivalents.

adapt(value)[source]

Adapt value to a slugified string.

Parameters:value – Any string-like value
class springfield.fields.StringField(default=Empty, doc=None, *args, **kwargs)[source]

A Field that contains a unicode string.

adapt(value)[source]

Adapt value to unicode.

type

alias of unicode

class springfield.fields.UrlField(default=Empty, doc=None, *args, **kwargs)[source]

Field with a URL value