This class is the base Class for all special flatty schema types. These are TypedList and TypedDict
sets the type for the inherited flatty schema class
Class for managing the converters
deletes the converter object for a given conv_type
sets a converter object for a given conv_type
conv_type: the type for which the converter is responsible
converter: a subclass of the Converter class
calls the right converter and converts to a flat type
val_type: the type of the object
obj: the object which should be converted
calls the right converter and converts the flat val to a schema object
val_type: the type to which we want to convert
val: the flattened data which needs to be converted here
Base class for all Converters. New converters of custom types can be build by inherit from this class and implement the following two methods
need to be implemented to convert a python object to a primitive
need to be implemented to convert a primitive to a python object
Converter for datetime.date
Converter for datetime.datetime
This class builds the base class for all schema classes. All schema classes must inherit from this class
>>> import flatty
>>>
>>> class Bar(flatty.Schema):
... a_num = int
... a_str = str
... a_thing = None
one way to flatten the instance of this class
one way to unflatten and load the data back in the schema objects
Converter for datetime.time
This class is used for typed dict. During flattening and unflattening the types are checked and restored.
>>> import flatty
>>>
>>>
>>> class Bar(flatty.Schema):
... a_num = int
... a_str = str
... a_thing = None
...
>>> class Foo(flatty.Schema):
... my_typed_dict = flatty.TypedDict.set_type(Bar)
>>>
>>>
>>> my_bar = Bar(a_num=42, a_str='hello world', a_thing='whatever type here')
>>> foo = Foo(my_typed_dict={'my_key':my_bar})
>>>
>>> flatted = foo.flatit()
>>> print flatted
{'my_typed_dict': {'my_key': {'a_num': 42, 'a_str': 'hello world', 'a_thing': 'whatever type here'}}}
>>>
>>> restored_obj = Foo.unflatit(flatted)
>>>
>>> isinstance(restored_obj, Foo)
True
>>> isinstance(restored_obj.my_typed_dict['my_key'], Bar)
True
This class is used for typed lists. During flattening and unflattening the types are checked and restored.
>>> import flatty
>>>
>>>
>>> class Bar(flatty.Schema):
... a_num = int
... a_str = str
... a_thing = None
...
>>> class Foo(flatty.Schema):
... my_typed_list = flatty.TypedList.set_type(Bar)
>>>
>>>
>>> my_bar = Bar(a_num=42, a_str='hello world', a_thing='whatever type here')
>>> foo = Foo(my_typed_list=[my_bar,])
>>>
>>> flatted = foo.flatit()
>>> print flatted
{'my_typed_list': [{'a_num': 42, 'a_str': 'hello world', 'a_thing': 'whatever type here'}]}
>>>
>>> restored_obj = Foo.unflatit(flatted)
>>>
>>> isinstance(restored_obj, Foo)
True
>>> isinstance(restored_obj.my_typed_list[0], Bar)
True
one way to flatten the obj
one way to unflatten and load the data back in the cls