def parse_iso_date(s):
 format = '%Y-%m-%dT%H:%M:%SZ'
 try:
  return datetime.datetime.strptime(s, format).replace(tzinfo=pytz.utc)
 except ValueError:
  return s

def parse_iso_date ( s ) : format = '%Y-%m-%dT%H:%M:%SZ' try : return datetime . datetime . strptime ( s , format ) . replace ( tzinfo = pytz . utc ) except ValueError : return s
parses an iso 8601 date string and returns a utc datetime object .