In Spyne, models are used to mark how a certain message fragment will be converted to and from which native python format. They are also used to hold both declarative and imperative restrictions.
Spyne has built-in support most common data types and provides an API to those who’d like to implement their own.
Bases: type
I hate quirks. So this is a 10-minute attempt to get rid of a one-letter quirk.
Bases: object
The base class for type markers. It defines the model interface for the interface generators to use and also manages class customizations that are mainly used for defining constraints on input values.
Bases: object
The class that holds the annotations for the given type.
Any object that carries app-specific info.
The public documentation for the given type.
Bases: object
The class that holds the constraints for the given type.
The default value if the input is None
If true, this field will be excluded from the interface document.
If true, this field will be excluded from the table mapper of the parent class.
If true, this field will be excluded from the table of the parent class.
If false, this object will be ignored in log_repr, mostly used for logging purposes.
Can be set to any strictly positive integer. Values greater than 1 will imply an iterable of objects as native python type. Can be set to decimal.Decimal("inf") for arbitrary number of arguments.
Set this to 1 to make this object mandatory. Can be set to any positive integer. Note that an object can still be null or empty, even if it’s there.
Set this to false to reject null values. Synonyms with nullable.
The tag used to add a primitives as child to a complex type in the xml schema.
A dict that will be passed to SQLAlchemy’s Column constructor as **kwargs.
A dict that contains locale codes as keys and translations of field names to that language as values.
Duplicates cls and overwrites the values in cls.Attributes with **kwargs and returns the new class.
Returns the namespace of the class. Defaults to the python module name.
Returns the namespace prefix for the given interface. The get_namespace_prefix of the interface class generates a prefix if none is defined.
Returns the class name unless the __type_name__ attribute is defined.
Returns the type name with a namespace prefix, separated by a column.
This call finalizes the namespace assignment. The default namespace is not available until the application calls populate_interface method of the interface generator.
Bases: spyne.model._base.ModelBase
The base class for primitives.
The spyne.model.binary package contains binary type markers.
Bases: spyne.model._base.SimpleModel
Canonical container for arbitrary data. Every protocol has a different way of encapsulating this type. E.g. xml-based protocols encode this as base64, while HttpRpc just hands it over.
Its native python format is a sequence of str objects for Python 2.x and a sequence of bytes objects for Python 3.x.
Bases: spyne.model._base.SimpleModel
A compact way of dealing with incoming files for protocols with a standard way of encoding file metadata along with binary data. (E.g. Http)
The spyne.model.complex module contains spyne.model.complex.ComplexBase class and its helper objects and subclasses. These are mainly container classes.
Bases: spyne.model.complex.ComplexModelBase
Different type_name, same _type_info.
Bases: spyne.model.complex.ComplexModelBase
This class generates a ComplexModel child that has one attribute that has the same name as the serialized class. It’s contained in a Python list.
Bases: spyne.model.complex.ComplexModelBase
The general complexType factory. The __call__ method of this class will return instances, contrary to primivites where the same call will result in customized duplicates of the original class definition. Those who’d like to customize the class should use the customize method. (see :class:spyne.model.ModelBase).
Bases: spyne.model._base.ModelBase
If you want to make a better class type, this is what you should inherit from.
Bases: spyne.model._base.Attributes
ComplexModel-specific attributes
The sqlalchemy mapper object
A dict that will be passed to sqlalchemy.orm.mapper() constructor as. **kwargs.
None or sqlalchemy.MetaData instance.
The sqlalchemy table object
A dict that will be passed to sqlalchemy.schema.Table constructor as **kwargs.
Table name.
Return an alias class for the given target class.
This function is a variation on ‘ComplexModel.produce’. The alias will borrow the target’s _type_info.
Duplicates cls and overwrites the values in cls.Attributes with **kwargs and returns the new class.
Get an empty native type so that the deserialization logic can set its attributes.
Returns a _type_info dict that includes members from all base classes.
It’s called a “flat” dict because it flattens all members from the inheritance hierarchy into one dict.
Returns the native object corresponding to the serialized form passed in the value argument.
Parameters: | value – This argument can be: * A list or tuple of native types aligned with cls._type_info. * A dict of native types. * The native type itself. If the value type is not a list, tuple or dict, the value is returned untouched. |
---|
Returns a _type_info dict that includes members from all base classes and whose types are only primitives. It will prefix field names in non-top-level complex objects with field name of its parent.
For example, given hier_delim=’_’; the following hierarchy:
{‘some_object’: [{‘some_string’: [‘abc’]}]}would be transformed to:
{‘some_object_some_string’: [‘abc’]}
Bases: type
This metaclass sets _type_info, __type_name__ and __extends__ which are going to be used for (de)serialization and schema generation.
Bases: spyne.model.complex.Array
This class generates a ComplexModel child that has one attribute that has the same name as the serialized class. It’s contained in a Python iterable. The distinction with the Array is made in the protocol implementation, this is just a marker.
Persistent storage serialization method values
Bases: object
Use this as a placeholder type in classes that contain themselves. See spyne.test.model.test_complex.TestComplexModel.test_self_reference().
A TableModel template that generates a new TableModel class for each call. If metadata is not supplied, a new one is instantiated.
Bases: spyne.model._base.ModelBase
Items which are marshalled as attributes of the parent element.
Bases: spyne.model.complex.XmlAttribute
Reference to an Xml attribute.
Complex argument to ComplexModelBase.Attributes.store_as for storing the class instance as a json document.
Make sure you don’t mix this with the json package when importing.
Use this function if you want to echo a ComplexModel subclass. It will limit output size of the String types, thus make your logs smaller.
Complex argument to ComplexModelBase.Attributes.store_as for storing the class instance as a row in a table in a relational database.
Parameters: |
|
---|
Complex argument to ComplexModelBase.Attributes.store_as for xml serialization.
Parameters: |
|
---|
The enum type that can only return True when compared to types of own type.
Here’s how it’s supposed to work:
>>> from spyne.model.enum import Enum
>>> SomeEnum = Enum("SomeValue", "SomeOtherValue", type_name="SomeEnum")
>>> SomeEnum.SomeValue == SomeEnum.SomeOtherValue
False
>>> SomeEnum.SomeValue == SomeEnum.SomeValue
True
>>> SomeEnum.SomeValue is SomeEnum.SomeValue
True
>>> SomeEnum.SomeValue == 0
False
>>> SomeEnum2 = Enum("SomeValue", "SomeOtherValue", type_name="SomeEnum")
>>> SomeEnum2.SomeValue == SomeEnum.SomeValue
False
In the above example, SomeEnum can be used as a regular Spyne model.
Bases: spyne.model._base.ModelBase, exceptions.Exception
Use this class as a base for all public exceptions. The Fault object adheres to the SOAP 1.1 Fault definition,
which has three main attributes:
Parameters: |
|
---|
The spyne.model.primitive package contains atomic, single-value types.
Bases: spyne.model._base.SimpleModel
A dict instance that can contain other dicts, iterables or primitive types. Its serialization is protocol-dependent.
Bases: spyne.model.primitive.Unicode
A special kind of String type designed to hold an uri.
Bases: object
A special object that is just a better way of carrying the information carried with a link.
Parameters: |
|
---|
Bases: spyne.model._base.SimpleModel
An xml node that can contain any number of sub nodes. It’s represented by an ElementTree object.
Bases: spyne.model._base.SimpleModel
Life is simple here. Just true or false.
Bases: spyne.model.primitive.DateTime
Just that, Date. No time zone support.
Native type is datetime.date.
Bases: spyne.model.primitive.Attributes
Customizable attributes of the spyne.model.primitive.Date type.
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.
The date should be greater than or equal to this date.
The date should be greater than this date.
The date should be lower than or equal to this date.
The date should be lower than this date.
A regular expression that matches the whole date. See here for more info: http://www.regular-expressions.info/xml.html
Bases: spyne.model._base.SimpleModel
A compact way to represent dates and times together. Supports time zones.
Native type is datetime.datetime.
Bases: spyne.model._base.Attributes
Customizable attributes of the spyne.model.primitive.DateTime type.
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.
The datetime should be greater than or equal to this datetime.
The datetime should be greater than this datetime.
The datetime should be lower than or equal to this datetime.
The datetime should be lower than this datetime.
A regular expression that matches the whole datetime. See here for more info: http://www.regular-expressions.info/xml.html
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
Bases: spyne.model._base.SimpleModel
The primitive that corresponds to the native python Decimal.
This is also the base class for denoting numbers.
Bases: spyne.model._base.Attributes
Customizable attributes of the spyne.model.primitive.Decimal type.
A regular python string formatting string. See here: http://docs.python.org/library/stdtypes.html#string-formatting
Maximum number of digits after the decimal separator.
The value should be greater than or equal to this number.
The value should be greater than this number.
The value should be lower than or equal to this number.
The value should be lower than this number.
The maximum length of string to be attempted to convert to number.
A regular expression that matches the whole field. See here for more info: http://www.regular-expressions.info/xml.html
Maximum number of digits.
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.
Bases: spyne.model._base.SimpleModel
Native type is datetime.timedelta.
Bases: spyne.model.primitive.Double
Synonym for Double (as far as python side of things are concerned). It’s here for compatibility reasons.
Bases: spyne.model.primitive.AnyUri
A special kind of String that holds the uri of an image.
Bases: spyne.model.primitive.Decimal
The arbitrary-size signed integer.
Bases: spyne.model.primitive.Integer
The 8-bit signed integer, aka short.
Bases: spyne.model.primitive.Integer
The 32-bit signed integer, aka int.
Bases: spyne.model.primitive.Integer
The 64-bit signed integer, aka long.
Bases: spyne.model.primitive.Integer
The 8-bit signed integer, aka byte.
Class that contains mandatory variants of primitives.
alias of UnsignedInteger
Bases: spyne.model.primitive.Unicode
An experimental point type whose native format is WKT. You can use shapely.wkt.loads() to get a proper point type.
Bases: spyne.model.primitive.Unicode
An experimental point type whose native format is WKT. You can use shapely.wkt.loads() to get a proper polygon type.
Bases: spyne.model._base.SimpleModel
Just that, Time. No time zone support.
Native type is datetime.time.
Bases: spyne.model._base.Attributes
Customizable attributes of the spyne.model.primitive.Time type.
The time should be greater than or equal to this time.
The time should be greater than this time.
The time should be lower than or equal to this time.
The time should be lower than this time.
A regular expression that matches the whole time. See here for more info: http://www.regular-expressions.info/xml.html
Bases: spyne.model._base.SimpleModel
The type to represent human-readable data. Its native format is unicode or str with given encoding.
Bases: spyne.model._base.Attributes
Customizable attributes of the spyne.model.primitive.Unicode type.
The encoding of str objects this class may have to deal with.
A regular python string formatting string. See here: http://docs.python.org/library/stdtypes.html#string-formatting
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.
Minimum length of string. Can be set to any positive integer
A regular expression that matches the whole string. See here for more info: http://www.regular-expressions.info/xml.html
The argument to the unicode builtin; one of ‘strict’, ‘replace’ or ‘ignore’.
alias of UnsignedInteger8
alias of UnsignedInteger32
Bases: spyne.model.primitive.Integer
The arbitrary-size unsigned integer, aka nonNegativeInteger.
Bases: spyne.model.primitive.Integer
The 16-bit unsigned integer, aka unsignedShort.
Bases: spyne.model.primitive.UnsignedInteger
The 32-bit unsigned integer, aka unsignedInt.
Bases: spyne.model.primitive.UnsignedInteger
The 64-bit unsigned integer, aka unsignedLong.
Bases: spyne.model.primitive.Integer
The 8-bit unsigned integer, aka unsignedByte.
alias of UnsignedInteger64
alias of UnsignedInteger16
This module is DEPRECATED. Create your own TableModel using spyne.model.complex.TTableModel()
Bases: spyne.model.complex.ComplexModelBase
The main base class for complex types shared by both SQLAlchemy and spyne. Classes that inherit from this class should also inherit from an sqlalchemy.declarative base class. See the SQLAlchemy Integration section for more info.
Bases: sqlalchemy.ext.declarative.api.DeclarativeMeta, spyne.model.complex.ComplexModelMeta
This class uses the information in class definition dictionary to build the _type_info dictionary that spyne relies on. It otherwise leaves SQLAlchemy and its information alone.