def utcstr(ts):
    """
    Format UTC timestamp in ISO 8601 format.

    :param ts: The timestamp to format.
    :type ts: instance of :py:class:`datetime.datetime`

    :returns: Timestamp formatted in ISO 8601 format.
    :rtype: unicode
    """
    if ts:
        return ts.strftime("%Y-%m-%dT%H:%M:%S.%f")[:-3] + "Z"
    else:
        return ts