def to_iso(obj):
    if isinstance(obj, basestring) or obj is None:
        return obj
    elif isinstance(obj, datetime):
        timestamp = obj.isoformat()
        if ('+' not in timestamp and len(timestamp) == 19 and
            not timestamp.endswith('Z')):
            timestamp += 'Z' # UTC
        return timestamp
    else:
        raise Exception("Unable to convert %s to an ISO 8601 timestampe." %
                        obj)
Converts datetime object to an ISO 8601 timestamp.
dataset/ETHPy150Open Kloudless/kloudless-python/kloudless/util.py/to_iso