The spyne.model package contains the Spyne type markers to denote primitive and complex types in object and method definitions.
Spyne has built-in support for most common data types and provides an API for those who’d like to implement their own.
There are five types of models in Spyne:
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.
This holds the original class the class .customize()d from. Ie if this is None, the class is not a customize()d one.
This holds the original class the class inherited or .customize()d from. This is different from __orig__ because it’s only set when cls.is_default(cls) == False
The public namespace of this class. Use get_namespace() instead of accessing it directly.
The public type name of the class. Use get_type_name() instead of accessing it directly.
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.
When not None, it overrides Spyne’s own mapping from Spyne types to SQLAlchemy types. It’s a standard SQLAlchemy type marker, e.g. sqlalchemy.Integer.
The default value if the input is None
The default value if the input is None
When the incoming object is empty (e.g. ‘’ for strings) treat it as None. No effect (yet) for outgoing values.
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.
Can be True, a string, or a tuple of two strings.
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. True by default. The default value can be changed by
setting AttributesMeta.NULLABLE_DEFAULT.
An integer that’s passed to _type_info.insert() as first argument when not None. .append() is used otherwise.
to be implemented.
If True, the attribute won’t be initialized from outside values.
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.
This specifies which string should be used as field name when this type is seriazed under a ComplexModel.
An Xml-specific attribute that specifies which namespace should be used for field names in classes.
Database table name.
A dict that contains locale codes as keys and translations of field names to that language as values.
If True, this object will be set as unique in the database schema with default indexing options. If the value is a string, it will be used as the indexing method to create the unique index. See sqlalchemy documentation on how to create multi-column unique constraints.
When not None, shares the same <choice> tag with fields with the same xml_choice_group value.
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.
Returns str(value). This should be overridden if this is not enough.
Override this method to do your own input validation on the native value. This is called after converting the incoming string to the native python value.
Override this method to do your own input validation on the input string. This is called before converting the incoming string to the native python value.
Bases: spyne.model._base.ModelBase
The base class for primitives.
Bases: spyne.model._base.Attributes
The class that holds the constraints for the given type.
The set of possible values for this type.
Overriden so that any attempt to instantiate a primitive will return a customized class instead of an instance.
See spyne.model.base.ModelBase for more information.
Duplicates cls and overwrites the values in cls.Attributes with **kwargs and returns the new class.