from datetime import datetime
datetime.now().isoformat()
# Out: '2016-07-31T23:08:20.886783'
from datetime import datetime
from dateutil.tz import tzlocal
datetime.now(tzlocal()).isoformat()
# Out: '2016-07-31T23:09:43.535074-07:00'
from datetime import datetime
from dateutil.tz import tzlocal
datetime.now(tzlocal()).replace(microsecond=0).isoformat()
# Out: '2016-07-31T23:10:30-07:00'
See ISO 8601 for more information about the ISO 8601 format.