kylie package¶
Module contents¶
kylie - A module for mapping between JSON and Python classes.
- class kylie.Attribute(struct_name=None, python_type=None, serialized_type=None)¶
Bases: object
Define a persistent attribute on a Model subclass.
By default the attribute will use the attribute’s name on the Model as the key in the serialized dict. If struct_name is provided, that will be used as the dict key.
python_type, if provided should be a function that takes the serialized value and converts it to the type that will be stored on the Model instance. This parameter is the usually used with, and is the opposite of serialized_type.
serialized_type, if provided, should be a function that takes the value stored on the Model instance and returns a value that should be stored in the serialized dict. This parameter is the usually used with, and is the opposite of python_type.
- pack(instance, d)¶
Store the attribute on the provided dictionary, d.
- struct_name¶
The name of the attribute when it is persisted.
This is either calculated from the attribute’s name on the Model it is assigned to, or provided by the constructor’s struct_name parameter.
- unpack(instance, element)¶
Unpack the data item, provided as element, and store on the instance.
- class kylie.Relation(relation_class, struct_name=None, sequence=False)¶
Bases: kylie.kylie.Attribute
An Attribute that links to another Model.
- pack(instance, d)¶
Serialize the provided instance and store in the provided dict d.
- unpack(instance, element)¶
Create a new instance of the relation_class and deserialize the provided element into it.