API Reference

coercion.__version__ = '1.0.0'

str(object=’‘) -> string

Return a nice string representation of the object. If the argument is a string, the return value is the same object.

coercion.version_info = (1, 0, 0)

tuple() -> empty tuple tuple(iterable) -> tuple initialized from iterable’s items

If the argument is a tuple, the return value is the same object.

coercion.stringify(obj)

Return the string representation of an object.

Parameters:obj – object to get the representation of
Returns:unicode string representation of obj or obj unchanged

This function returns a string representation for many of the types from the standard library. It does not convert numeric or Boolean values to strings – it only converts non-primitive instances such as datetime.datetime. The following table describes the types that are handled and describes how they are represented.

Class Behavior
uuid.UUID str(obj)
datetime.datetime obj.strftime('%Y-%m-%dT%H:%M:%S.%f%z')
memoryview obj.tobytes().decode('utf-8')
bytearray bytes(obj).decode('utf-8')
buffer bytes(obj).decode('utf-8')
bytes obj.decode('utf-8')

Other types are returned unharmed.

coercion.normalize_collection(coll)

Normalize all elements in a collection.

Parameters:coll – the collection to normalize. This is required to implement one of the following protocols: collections.Mapping, collections.Sequence, or collections.Set.
Returns:a new instance of the input class with the keys and values normalized via stringify()
Raises:RuntimeError if coll is not a collection

This function transforms the collection by recursively transforming each key and value contained in it. The action is recursive but the implementation is unrolled and iterative. If you are interested in the algorithm used, it is described as comments in the code.