flywheel.fields.types module

Field type definitions

class flywheel.fields.types.BinaryType[source]

Bases: flywheel.fields.types.TypeDefinition

Binary strings, stored as a str/bytes

aliases = ['B', <class 'dynamo3.types.Binary'>][source]
coerce(value, force)[source]

Check the type of a value and possible convert it

Parameters:
value : object

The value to check

force : bool

If True, always attempt to convert a bad type to the correct type

Returns:
value : object

A variable of the correct type

Raises:
exc : TypeError or ValueError

If the value is the incorrect type and could not be converted

data_type[source]

alias of __builtin__.str

ddb_data_type = 'B'[source]
ddb_dump(value)[source]

Dump a value to a form that can be stored in DynamoDB

ddb_load(value)[source]

Turn a value into this type from a DynamoDB value

class flywheel.fields.types.BoolType[source]

Bases: flywheel.fields.types.TypeDefinition

Boolean type

coerce(value, force)[source]

Check the type of a value and possible convert it

Parameters:
value : object

The value to check

force : bool

If True, always attempt to convert a bad type to the correct type

Returns:
value : object

A variable of the correct type

Raises:
exc : TypeError or ValueError

If the value is the incorrect type and could not be converted

data_type[source]

alias of __builtin__.bool

ddb_data_type = 'BOOL'[source]
class flywheel.fields.types.DateTimeType(naive=False)[source]

Bases: flywheel.fields.types.TypeDefinition

Datetimes, stored as a unix timestamp

Parameters:
naive : bool, optional

If True, will load values from Dynamo with no timezone. If False, will add a UTC timezone. (Default False).

Notes

If you want to use naive datetimes, you will need to reference the type class directly instead of going through an alias. For example:

from flywheel.fields.types import DateTimeType

field = Field(data_type=DateTimeType(naive=True))
data_type[source]

alias of datetime.datetime

ddb_data_type = 'N'[source]
ddb_dump(value)[source]

Dump a value to a form that can be stored in DynamoDB

ddb_load(value)[source]

Turn a value into this type from a DynamoDB value

class flywheel.fields.types.DateType[source]

Bases: flywheel.fields.types.TypeDefinition

Dates, stored as timestamps

data_type[source]

alias of datetime.date

ddb_data_type = 'N'[source]
ddb_dump(value)[source]

Dump a value to a form that can be stored in DynamoDB

ddb_load(value)[source]

Turn a value into this type from a DynamoDB value

class flywheel.fields.types.DecimalType[source]

Bases: flywheel.fields.types.TypeDefinition

Numerical values that use Decimal in the application layer.

This should be used if you want to work with floats but need the additional precision of the Decimal type.

coerce(value, force)[source]

Check the type of a value and possible convert it

Parameters:
value : object

The value to check

force : bool

If True, always attempt to convert a bad type to the correct type

Returns:
value : object

A variable of the correct type

Raises:
exc : TypeError or ValueError

If the value is the incorrect type and could not be converted

data_type[source]

alias of decimal.Decimal

ddb_data_type = 'N'[source]
class flywheel.fields.types.DictType[source]

Bases: flywheel.fields.types.TypeDefinition

Dict type, stored as a map

coerce(value, force)[source]

Check the type of a value and possible convert it

Parameters:
value : object

The value to check

force : bool

If True, always attempt to convert a bad type to the correct type

Returns:
value : object

A variable of the correct type

Raises:
exc : TypeError or ValueError

If the value is the incorrect type and could not be converted

data_type[source]

alias of __builtin__.dict

ddb_data_type = 'M'[source]
mutable = True[source]
class flywheel.fields.types.FloatType[source]

Bases: flywheel.fields.types.TypeDefinition

Float values

coerce(value, force)[source]

Check the type of a value and possible convert it

Parameters:
value : object

The value to check

force : bool

If True, always attempt to convert a bad type to the correct type

Returns:
value : object

A variable of the correct type

Raises:
exc : TypeError or ValueError

If the value is the incorrect type and could not be converted

data_type[source]

alias of __builtin__.float

ddb_data_type = 'N'[source]
ddb_load(value)[source]

Turn a value into this type from a DynamoDB value

class flywheel.fields.types.IntType[source]

Bases: flywheel.fields.types.TypeDefinition

Integer values (includes longs)

aliases = [<type 'int'>, <type 'long'>][source]
coerce(value, force)[source]

Check the type of a value and possible convert it

Parameters:
value : object

The value to check

force : bool

If True, always attempt to convert a bad type to the correct type

Returns:
value : object

A variable of the correct type

Raises:
exc : TypeError or ValueError

If the value is the incorrect type and could not be converted

data_type[source]

alias of __builtin__.int

ddb_data_type = 'N'[source]
ddb_load(value)[source]

Turn a value into this type from a DynamoDB value

class flywheel.fields.types.ListType[source]

Bases: flywheel.fields.types.TypeDefinition

List type

coerce(value, force)[source]

Check the type of a value and possible convert it

Parameters:
value : object

The value to check

force : bool

If True, always attempt to convert a bad type to the correct type

Returns:
value : object

A variable of the correct type

Raises:
exc : TypeError or ValueError

If the value is the incorrect type and could not be converted

data_type[source]

alias of __builtin__.list

ddb_data_type = 'L'[source]
mutable = True[source]
class flywheel.fields.types.NumberType[source]

Bases: flywheel.fields.types.TypeDefinition

Any kind of numerical value

coerce(value, force)[source]

Check the type of a value and possible convert it

Parameters:
value : object

The value to check

force : bool

If True, always attempt to convert a bad type to the correct type

Returns:
value : object

A variable of the correct type

Raises:
exc : TypeError or ValueError

If the value is the incorrect type and could not be converted

data_type = 'N'[source]
ddb_data_type = 'N'[source]
ddb_load(value)[source]

Turn a value into this type from a DynamoDB value

class flywheel.fields.types.SetType(item_type=None, type_class=None)[source]

Bases: flywheel.fields.types.TypeDefinition

Set types

classmethod bind(item_type)[source]

Create a set factory that will contain a specific data type

coerce(value, force)[source]

Check the type of a value and possible convert it

Parameters:
value : object

The value to check

force : bool

If True, always attempt to convert a bad type to the correct type

Returns:
value : object

A variable of the correct type

Raises:
exc : TypeError or ValueError

If the value is the incorrect type and could not be converted

data_type[source]

alias of __builtin__.set

ddb_dump(value)[source]

Dump a value to a form that can be stored in DynamoDB

ddb_dump_inner(value)[source]

We need to expose this for ‘contains’ and ‘ncontains’

ddb_load(value)[source]

Turn a value into this type from a DynamoDB value

mutable = True[source]
class flywheel.fields.types.StringType[source]

Bases: flywheel.fields.types.TypeDefinition

String values, stored as unicode

aliases = ['S'][source]
coerce(value, force)[source]

Check the type of a value and possible convert it

Parameters:
value : object

The value to check

force : bool

If True, always attempt to convert a bad type to the correct type

Returns:
value : object

A variable of the correct type

Raises:
exc : TypeError or ValueError

If the value is the incorrect type and could not be converted

data_type[source]

alias of __builtin__.unicode

ddb_data_type = 'S'[source]
class flywheel.fields.types.TypeDefinition[source]

Bases: flywheel.compat.UnicodeMixin

Base class for all Field types

Attributes:
data_type : object

The value you wish to pass in to Field as the data_type.

aliases : list

Other values that will reference this type if passed to Field

ddb_data_type : {STRING, BINARY, NUMBER, STRING_SET, BINARY_SET, NUMBER_SET, BOOL, LIST, MAP}

The DynamoDB data type that backs this type

mutable : bool

If True, flywheel will track updates to this field automatically when making calls to sync()

allowed_filters : set

The set of filters that can be used on this field type

aliases = [][source]
coerce(value, force)[source]

Check the type of a value and possible convert it

Parameters:
value : object

The value to check

force : bool

If True, always attempt to convert a bad type to the correct type

Returns:
value : object

A variable of the correct type

Raises:
exc : TypeError or ValueError

If the value is the incorrect type and could not be converted

data_type = None[source]
ddb_data_type = None[source]
ddb_dump(value)[source]

Dump a value to a form that can be stored in DynamoDB

ddb_dump_inner(value)[source]

If this is a set type, dump a value to the type contained in the set

ddb_load(value)[source]

Turn a value into this type from a DynamoDB value

mutable = False[source]
class flywheel.fields.types.UTCTimezone[source]

Bases: datetime.tzinfo

UTC

dst(dt)[source]

datetime -> DST offset in minutes east of UTC.

tzname(dt)[source]

datetime -> string name of time zone.

utcoffset(dt)[source]

datetime -> minutes east of UTC (negative for west of UTC).

flywheel.fields.types.register_type(type_class, allow_in_set=True)[source]

Register a type class for use with Fields

flywheel.fields.types.set_(data_type)[source]

Create an alias for a SetType that contains this data type