Previous topic

Models

Next topic

Binary Types

This Page

Primitives

The spyne.model.primitive package contains types with values that fit in a single field.

See spyne.protocol._model for {to,from}_string implementations.

class spyne.model.primitive.AnyDict[source]

Bases: spyne.model._base.SimpleModel

A dict instance that can contain other dicts, iterables or primitive types. Its serialization is protocol-dependent.

classmethod customize(**kwargs)[source]

Duplicates cls and overwrites the values in cls.Attributes with **kwargs and returns the new class.

class spyne.model.primitive.AnyUri[source]

Bases: spyne.model.primitive.Unicode

A special kind of String type designed to hold an uri.

class Value(href, text=None, content=None)[source]

Bases: object

A special object that is just a better way of carrying the information carried with a link.

Parameters:
  • href – The uri string.
  • text – The text data that goes with the link. This is a str or a unicode instance.
  • content – The structured data that goes with the link. This is an lxml.etree.Element instance.
class spyne.model.primitive.AnyXml[source]

Bases: spyne.model._base.SimpleModel

An xml node that can contain any number of sub nodes. It’s represented by an ElementTree object.

class spyne.model.primitive.Boolean[source]

Bases: spyne.model._base.SimpleModel

Life is simple here. Just true or false.

spyne.model.primitive.Byte

The 8-bit signed integer, alias for Integer8.

alias of _BoundedInteger

class spyne.model.primitive.Date[source]

Bases: spyne.model.primitive.DateTime

Just that, Date. No time zone support.

Native type is datetime.date.

class Attributes[source]

Bases: spyne.model.primitive.Attributes

Customizable attributes of the spyne.model.primitive.Date type.

format = '%Y-%m-%d'

DateTime format fed to the strftime function. See: http://docs.python.org/library/datetime.html?highlight=strftime#strftime-strptime-behavior Ignored by protocols like SOAP which have their own ideas about how Date objects should be serialized.

ge = datetime.date(1, 1, 1)

The date should be greater than or equal to this date.

gt = datetime.date(1, 1, 1)

The date should be greater than this date.

le = datetime.date(9999, 12, 31)

The date should be lower than or equal to this date.

lt = datetime.date(9999, 12, 31)

The date should be lower than this date.

pattern = None

A regular expression that matches the whole date. See here for more info: http://www.regular-expressions.info/xml.html

class spyne.model.primitive.DateTime[source]

Bases: spyne.model._base.SimpleModel

A compact way to represent dates and times together. Supports time zones. Working with timezones is a bit quirky – Spyne works very hard to have all datetimes with time zones internally and only strips them when explicitly requested with timezone=False. See DateTime.Attributes.as_timezone for more information.

Native type is datetime.datetime.

class Attributes[source]

Bases: spyne.model._base.Attributes

Customizable attributes of the spyne.model.primitive.DateTime type.

as_timezone = None
When not None, converts:
  • Outgoing values to the given time zone (by calling .astimezone()).

  • Incoming values without tzinfo to the given time zone by calling .replace(tzinfo=<as_timezone>) and values with tzinfo to the

    given timezone by calling .astimezone().

Either None or a return value of pytz.timezone()

When this is None and a datetime with tzinfo=None comes in, it’s converted to spyne.LOCAL_TZ which defaults to pytz.utc. You can use tzlocal to set it to local time right after import spyne.

format = None

DateTime format fed to the strftime function. See: http://docs.python.org/library/datetime.html?highlight=strftime#strftime-strptime-behavior Ignored by protocols like SOAP which have their own ideas about how DateTime objects should be serialized.

ge = datetime.datetime(1, 1, 1, 0, 0, tzinfo=<UTC>)

The datetime should be greater than or equal to this datetime. It must always have a timezone.

gt = datetime.datetime(1, 1, 1, 0, 0, tzinfo=<UTC>)

The datetime should be greater than this datetime. It must always have a timezone.

le = datetime.datetime(9999, 12, 31, 23, 59, 59, 999999, tzinfo=<UTC>)

The datetime should be lower than or equal to this datetime. It must always have a timezone.

lt = datetime.datetime(9999, 12, 31, 23, 59, 59, 999999, tzinfo=<UTC>)

The datetime should be lower than this datetime. It must always have a timezone.

pattern = None

A regular expression that matches the whole datetime. See here for more info: http://www.regular-expressions.info/xml.html

serialize_as = None

One of (None, ‘sec’, ‘sec_float’, ‘msec’, ‘msec_float’, ‘usec’)

string_format = None

A regular python string formatting string. %s will contain the date string. See here for more info: http://docs.python.org/library/stdtypes.html#string-formatting

timezone = True

If False, time zone info is stripped before serialization. Also makes sqlalchemy schema generator emit ‘timestamp without timezone’.

class spyne.model.primitive.Decimal[source]

Bases: spyne.model._base.SimpleModel

The primitive that corresponds to the native python Decimal.

This is also the base class for denoting numbers.

Note that it is your responsibility to make sure that the scale and precision constraints set in this type is consistent with the values in the context of the decimal package. See the decimal.getcontext() documentation for more information.

class Attributes[source]

Bases: spyne.model._base.Attributes

Customizable attributes of the spyne.model.primitive.Decimal type.

format = None

A regular python string formatting string. See here: http://docs.python.org/library/stdtypes.html#string-formatting

fraction_digits = Decimal('Infinity')

Maximum number of digits after the decimal separator.

ge = Decimal('-Infinity')

The value should be greater than or equal to this number.

gt = Decimal('-Infinity')

The value should be greater than this number.

le = Decimal('Infinity')

The value should be lower than or equal to this number.

lt = Decimal('Infinity')

The value should be lower than this number.

max_bound = None

Hardware limit that determines the highest value this type can store.

max_str_len = 1024

The maximum length of string to be attempted to convert to number.

min_bound = None

Hardware limit that determines the lowest value this type can store.

pattern = None

A regular expression that matches the whole field. See here for more info: http://www.regular-expressions.info/xml.html

str_format = None

A regular python string formatting string used by invoking its format() function. See here: http://docs.python.org/2/library/string.html#format-string-syntax

total_digits = Decimal('Infinity')

Maximum number of digits.

class spyne.model.primitive.Double[source]

Bases: spyne.model.primitive.Decimal

This is serialized as the python float. So this type comes with its gotchas. Unless you really know what you’re doing, you should use a Decimal with a pre-defined number of integer and decimal digits.

class spyne.model.primitive.Duration[source]

Bases: spyne.model._base.SimpleModel

Native type is datetime.timedelta.

class spyne.model.primitive.Float[source]

Bases: spyne.model.primitive.Double

Synonym for Double (as far as python side of things are concerned). It’s here for compatibility reasons.

class spyne.model.primitive.ImageUri[source]

Bases: spyne.model.primitive.AnyUri

A special kind of String that holds the uri of an image.

spyne.model.primitive.Int

The 32-bit signed integer, alias for Integer32.

alias of _BoundedInteger

class spyne.model.primitive.Integer[source]

Bases: spyne.model.primitive.Decimal

The arbitrary-size signed integer.

spyne.model.primitive.Integer16

The 16-bit signed integer, also known as short.

alias of _BoundedInteger

spyne.model.primitive.Integer32

The 64-bit signed integer, also known as int.

alias of _BoundedInteger

spyne.model.primitive.Integer64

The 64-bit signed integer, also known as long.

alias of _BoundedInteger

spyne.model.primitive.Integer8

The 8-bit signed integer, also known as byte.

alias of _BoundedInteger

class spyne.model.primitive.Line[source]

Bases: spyne.model.primitive.Unicode

A line type whose native format is a WKT string. You can use shapely.wkt.loads() to get a proper line type.

It’s a subclass of the Unicode type, so regular Unicode constraints apply. The only additional parameter is the number of dimensions.

Parameters:dim – Number of dimensons.
spyne.model.primitive.LineString

alias of Line

spyne.model.primitive.Long

The 64-bit signed integer, alias for Integer64.

alias of _BoundedInteger

class spyne.model.primitive.MultiLine[source]

Bases: spyne.model.primitive.Unicode

A MultiLine type whose native format is a WKT string. You can use shapely.wkt.loads() to get a proper MultiLine type.

It’s a subclass of the Unicode type, so regular Unicode constraints apply. The only additional parameter is the number of dimensions.

Parameters:dim – Number of dimensons.
spyne.model.primitive.MultiLineString

alias of MultiLine

class spyne.model.primitive.MultiPoint[source]

Bases: spyne.model.primitive.Unicode

A MultiPoint type whose native format is a WKT string. You can use shapely.wkt.loads() to get a proper MultiPoint type.

It’s a subclass of the Unicode type, so regular Unicode constraints apply. The only additional parameter is the number of dimensions.

Parameters:dim – Number of dimensons.
class spyne.model.primitive.MultiPolygon[source]

Bases: spyne.model.primitive.Unicode

A MultiPolygon type whose native format is a WKT string. You can use shapely.wkt.loads() to get a proper MultiPolygon type.

It’s a subclass of the Unicode type, so regular Unicode constraints apply. The only additional parameter is the number of dimensions.

Parameters:dim – Number of dimensons.
spyne.model.primitive.NonNegativeInteger

The arbitrary-size unsigned integer, alias for UnsignedInteger.

alias of UnsignedInteger

class spyne.model.primitive.Point[source]

Bases: spyne.model.primitive.Unicode

A point type whose native format is a WKT string. You can use shapely.wkt.loads() to get a proper point type.

It’s a subclass of the Unicode type, so regular Unicode constraints apply. The only additional parameter is the number of dimensions.

Parameters:dim – Number of dimensons.
class spyne.model.primitive.Polygon[source]

Bases: spyne.model.primitive.Unicode

A polygon type whose native format is a WKT string. You can use shapely.wkt.loads() to get a proper polygon type.

It’s a subclass of the Unicode type, so regular Unicode constraints apply. The only additional parameter is the number of dimensions.

Parameters:dim – Number of dimensons.
class spyne.model.primitive.PositiveInteger[source]

Bases: spyne.model.primitive.UnsignedInteger

The arbitrary-size positive integer (natural number).

spyne.model.primitive.Short

The 16-bit signed integer, alias for Integer16.

alias of _BoundedInteger

class spyne.model.primitive.Time[source]

Bases: spyne.model._base.SimpleModel

Just that, Time. No time zone support.

Native type is datetime.time.

class Attributes[source]

Bases: spyne.model._base.Attributes

Customizable attributes of the spyne.model.primitive.Time type.

ge = datetime.time(0, 0)

The time should be greater than or equal to this time.

gt = datetime.time(0, 0)

The time should be greater than this time.

le = datetime.time(23, 59, 59, 999999)

The time should be lower than or equal to this time.

lt = datetime.time(23, 59, 59, 999999)

The time should be lower than this time.

pattern = None

A regular expression that matches the whole time. See here for more info: http://www.regular-expressions.info/xml.html

class spyne.model.primitive.Unicode[source]

Bases: spyne.model._base.SimpleModel

The type to represent human-readable data. Its native format is unicode or str with given encoding.

class Attributes[source]

Bases: spyne.model._base.Attributes

Customizable attributes of the spyne.model.primitive.Unicode type.

encoding = None

The encoding of str objects this class may have to deal with.

format = None

A regular python string formatting string. See here: http://docs.python.org/library/stdtypes.html#string-formatting

max_len = Decimal('Infinity')

Maximum length of string. Can be set to decimal.Decimal('inf') to accept strings of arbitrary length. You may also need to adjust spyne.server.wsgi.MAX_CONTENT_LENGTH.

min_len = 0

Minimum length of string. Can be set to any positive integer

pattern = None

A regular expression that matches the whole string. See here for more info: http://www.regular-expressions.info/xml.html

unicode_errors = 'strict'

The argument to the unicode builtin; one of ‘strict’, ‘replace’ or ‘ignore’.

spyne.model.primitive.UnsignedByte

The 8-bit unsigned integer, alias for UnsignedInteger8.

alias of _BoundedUnsignedInteger

spyne.model.primitive.UnsignedInt

The 32-bit unsigned integer, alias for UnsignedInteger32.

alias of _BoundedUnsignedInteger

class spyne.model.primitive.UnsignedInteger[source]

Bases: spyne.model.primitive.Integer

The arbitrary-size unsigned integer, also known as nonNegativeInteger.

spyne.model.primitive.UnsignedInteger16

The 16-bit unsigned integer, also known as unsignedShort.

alias of _BoundedUnsignedInteger

spyne.model.primitive.UnsignedInteger32

The 64-bit unsigned integer, also known as unsignedInt.

alias of _BoundedUnsignedInteger

spyne.model.primitive.UnsignedInteger64

The 64-bit unsigned integer, also known as unsignedLong.

alias of _BoundedUnsignedInteger

spyne.model.primitive.UnsignedInteger8

The 8-bit unsigned integer, also known as unsignedByte.

alias of _BoundedUnsignedInteger

spyne.model.primitive.UnsignedLong

The 64-bit unsigned integer, alias for UnsignedInteger64.

alias of _BoundedUnsignedInteger

spyne.model.primitive.UnsignedShort

The 16-bit unsigned integer, alias for UnsignedInteger16.

alias of _BoundedUnsignedInteger

class spyne.model.primitive.Uuid[source]

Bases: spyne.model.primitive.Unicode

Unicode subclass for Universially-Unique Identifiers.