def datetime_to_isoformat(dt):
#=============================
  """
  Convert a Python datetime to an ISO 8601 representation.

  :param dt: A Python :class:~`datetime.datetime`.
  :return: A string representation of the date and time formatted as ISO 8601.
  """
  iso = dt.isoformat()
  if iso.endswith('+00:00'): return iso[:-6] + 'Z'
  else:                      return iso