{"id":13494284,"url":"https://github.com/closeio/ciso8601","last_synced_at":"2025-05-13T19:14:31.197Z","repository":{"id":17770490,"uuid":"20633992","full_name":"closeio/ciso8601","owner":"closeio","description":"Fast ISO8601 date time parser for Python written in C","archived":false,"fork":false,"pushed_at":"2024-12-09T12:53:48.000Z","size":252,"stargazers_count":567,"open_issues_count":15,"forks_count":45,"subscribers_count":31,"default_branch":"master","last_synced_at":"2025-05-05T01:37:17.157Z","etag":null,"topics":["c","date-parser","date-time","iso8601","python","rfc-3339"],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/closeio.png","metadata":{"files":{"readme":"README.rst","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2014-06-09T04:04:12.000Z","updated_at":"2025-04-30T10:37:46.000Z","dependencies_parsed_at":"2023-01-13T19:29:34.614Z","dependency_job_id":"1b11e236-d6ff-42b9-97f6-aef117020c10","html_url":"https://github.com/closeio/ciso8601","commit_stats":{"total_commits":187,"total_committers":24,"mean_commits":7.791666666666667,"dds":0.6898395721925134,"last_synced_commit":"aa7447797ccf78dac8092545dd53066926c382cb"},"previous_names":[],"tags_count":17,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/closeio%2Fciso8601","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/closeio%2Fciso8601/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/closeio%2Fciso8601/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/closeio%2Fciso8601/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/closeio","download_url":"https://codeload.github.com/closeio/ciso8601/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253655899,"owners_count":21943071,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c","date-parser","date-time","iso8601","python","rfc-3339"],"created_at":"2024-07-31T19:01:23.476Z","updated_at":"2025-05-13T19:14:31.178Z","avatar_url":"https://github.com/closeio.png","language":"Python","readme":"========\nciso8601\n========\n\n.. image:: https://img.shields.io/circleci/project/github/closeio/ciso8601.svg\n    :target: https://circleci.com/gh/closeio/ciso8601/tree/master\n\n.. image:: https://img.shields.io/pypi/v/ciso8601.svg\n    :target: https://pypi.org/project/ciso8601/\n\n.. image:: https://img.shields.io/pypi/pyversions/ciso8601.svg\n    :target: https://pypi.org/project/ciso8601/\n\n``ciso8601`` converts `ISO 8601`_ or `RFC 3339`_ date time strings into Python datetime objects.\n\nSince it's written as a C module, it is much faster than other Python libraries.\nTested with cPython 2.7, 3.4, 3.5, 3.6, 3.7, 3.8, 3.9, 3.10, 3.11, 3.12, 3.13.\n\n.. _ISO 8601: https://en.wikipedia.org/wiki/ISO_8601\n.. _RFC 3339: https://tools.ietf.org/html/rfc3339\n\n(Interested in working on projects like this? `Close`_ is looking for `great engineers`_ to join our team)\n\n.. _Close: https://close.com\n.. _great engineers: https://jobs.close.com\n\n\n.. contents:: Contents\n\n\nQuick start\n-----------\n\n.. code:: bash\n\n  % pip install ciso8601\n\n.. code:: python\n\n  In [1]: import ciso8601\n\n  In [2]: ciso8601.parse_datetime('2014-12-05T12:30:45.123456-05:30')\n  Out[2]: datetime.datetime(2014, 12, 5, 12, 30, 45, 123456, tzinfo=pytz.FixedOffset(330))\n\n  In [3]: ciso8601.parse_datetime('20141205T123045')\n  Out[3]: datetime.datetime(2014, 12, 5, 12, 30, 45)\n\nMigration to v2\n---------------\n\nVersion 2.0.0 of ``ciso8601`` changed the core implementation. This was not entirely backwards compatible, and care should be taken when migrating\nSee `CHANGELOG`_ for the Migration Guide.\n\n.. _CHANGELOG: https://github.com/closeio/ciso8601/blob/master/CHANGELOG.md\n\nWhen should I not use ``ciso8601``?\n-----------------------------------\n\n``ciso8601`` is not necessarily the best solution for every use case (especially since Python 3.11). See `Should I use ciso8601?`_\n\n.. _`Should I use ciso8601?`: https://github.com/closeio/ciso8601/blob/master/why_ciso8601.md\n\nError handling\n--------------\n\nStarting in v2.0.0, ``ciso8601`` offers strong guarantees when it comes to parsing strings.\n\n``parse_datetime(dt: String): datetime`` is a function that takes a string and either:\n\n* Returns a properly parsed Python datetime, **if and only if** the **entire** string conforms to the supported subset of ISO 8601\n* Raises a ``ValueError`` with a description of the reason why the string doesn't conform to the supported subset of ISO 8601\n\nIf time zone information is provided, an aware datetime object will be returned. Otherwise, a naive datetime is returned.\n\nBenchmark\n---------\n\nParsing a timestamp with no time zone information (e.g., ``2014-01-09T21:48:00``):\n\n.. \u003cinclude:benchmark_with_no_time_zone.rst\u003e\n\n.. table::\n\n    +--------------------------------+-----------+-----------+-----------+-----------+--------------------------------------------------+-+----------+----------+\n    |             Module             |Python 3.13|Python 3.12|Python 3.11|Python 3.10|Relative slowdown (versus ciso8601, latest Python)|…|Python 3.9|Python 3.8|\n    +================================+===========+===========+===========+===========+==================================================+=+==========+==========+\n    |ciso8601                        |64.8 nsec  |62.8 nsec  |60.1 nsec  |91.7 nsec  |N/A                                               |…|86 nsec   |92.9 nsec |\n    +--------------------------------+-----------+-----------+-----------+-----------+--------------------------------------------------+-+----------+----------+\n    |backports.datetime_fromisoformat|N/A        |N/A        |N/A        |73.6 nsec  |0.8x                                              |…|70 nsec   |75.9 nsec |\n    +--------------------------------+-----------+-----------+-----------+-----------+--------------------------------------------------+-+----------+----------+\n    |datetime (builtin)              |147 nsec   |138 nsec   |123 nsec   |N/A        |2.3x                                              |…|N/A       |N/A       |\n    +--------------------------------+-----------+-----------+-----------+-----------+--------------------------------------------------+-+----------+----------+\n    |pendulum                        |171 nsec   |181 nsec   |175 nsec   |214 nsec   |2.6x                                              |…|179 nsec  |180 nsec  |\n    +--------------------------------+-----------+-----------+-----------+-----------+--------------------------------------------------+-+----------+----------+\n    |udatetime                       |542 nsec   |563 nsec   |525 nsec   |555 nsec   |8.4x                                              |…|551 nsec  |553 nsec  |\n    +--------------------------------+-----------+-----------+-----------+-----------+--------------------------------------------------+-+----------+----------+\n    |str2date                        |3.29 usec  |3.53 usec  |3.52 usec  |3.85 usec  |50.8x                                             |…|3.72 usec |3.9 usec  |\n    +--------------------------------+-----------+-----------+-----------+-----------+--------------------------------------------------+-+----------+----------+\n    |iso8601utils                    |N/A        |N/A        |N/A        |N/A        |56.9x                                             |…|4.89 usec |4.89 usec |\n    +--------------------------------+-----------+-----------+-----------+-----------+--------------------------------------------------+-+----------+----------+\n    |iso8601                         |5.1 usec   |5.4 usec   |5.18 usec  |5.38 usec  |78.8x                                             |…|5.36 usec |5.55 usec |\n    +--------------------------------+-----------+-----------+-----------+-----------+--------------------------------------------------+-+----------+----------+\n    |isodate                         |5.76 usec  |5.85 usec  |5.21 usec  |5.91 usec  |89.0x                                             |…|5.97 usec |6.07 usec |\n    +--------------------------------+-----------+-----------+-----------+-----------+--------------------------------------------------+-+----------+----------+\n    |PySO8601                        |10 usec    |11.5 usec  |7.99 usec  |10.9 usec  |155.0x                                            |…|9.83 usec |9.81 usec |\n    +--------------------------------+-----------+-----------+-----------+-----------+--------------------------------------------------+-+----------+----------+\n    |aniso8601                       |12.1 usec  |12.5 usec  |11.1 usec  |15.1 usec  |186.9x                                            |…|15.4 usec |15.6 usec |\n    +--------------------------------+-----------+-----------+-----------+-----------+--------------------------------------------------+-+----------+----------+\n    |zulu                            |12.3 usec  |13.6 usec  |12.6 usec  |14.2 usec  |189.4x                                            |…|14.5 usec |14.2 usec |\n    +--------------------------------+-----------+-----------+-----------+-----------+--------------------------------------------------+-+----------+----------+\n    |maya                            |35.9 usec  |N/A        |40.6 usec  |46.7 usec  |554.3x                                            |…|45.4 usec |46.3 usec |\n    +--------------------------------+-----------+-----------+-----------+-----------+--------------------------------------------------+-+----------+----------+\n    |python-dateutil                 |36.2 usec  |36.9 usec  |36.1 usec  |44 usec    |558.5x                                            |…|46.4 usec |45.2 usec |\n    +--------------------------------+-----------+-----------+-----------+-----------+--------------------------------------------------+-+----------+----------+\n    |arrow                           |42.9 usec  |43.8 usec  |41.2 usec  |48.8 usec  |662.7x                                            |…|50.7 usec |50.1 usec |\n    +--------------------------------+-----------+-----------+-----------+-----------+--------------------------------------------------+-+----------+----------+\n    |metomi-isodatetime              |828 usec   |822 usec   |791 usec   |1.09 msec  |12781.0x                                          |…|1.1 msec  |1.11 msec |\n    +--------------------------------+-----------+-----------+-----------+-----------+--------------------------------------------------+-+----------+----------+\n    |moment                          |1.28 msec  |1.32 msec  |1.29 msec  |1.36 msec  |19696.9x                                          |…|1.37 msec |1.34 msec |\n    +--------------------------------+-----------+-----------+-----------+-----------+--------------------------------------------------+-+----------+----------+\n\nciso8601 takes 64.8 nsec, which is **2.3x faster than datetime (builtin)**, the next fastest Python 3.13 parser in this comparison.\n\n.. \u003c/include:benchmark_with_no_time_zone.rst\u003e\n\nParsing a timestamp with time zone information (e.g., ``2014-01-09T21:48:00-05:30``):\n\n.. \u003cinclude:benchmark_with_time_zone.rst\u003e\n\n.. table::\n\n    +--------------------------------+-----------+-----------+-----------+-----------+--------------------------------------------------+-+----------+----------+\n    |             Module             |Python 3.13|Python 3.12|Python 3.11|Python 3.10|Relative slowdown (versus ciso8601, latest Python)|…|Python 3.9|Python 3.8|\n    +================================+===========+===========+===========+===========+==================================================+=+==========+==========+\n    |ciso8601                        |73.9 nsec  |71 nsec    |65.6 nsec  |97.5 nsec  |N/A                                               |…|92.9 nsec |96.6 nsec |\n    +--------------------------------+-----------+-----------+-----------+-----------+--------------------------------------------------+-+----------+----------+\n    |backports.datetime_fromisoformat|N/A        |N/A        |N/A        |99.2 nsec  |1.0x                                              |…|93 nsec   |99.4 nsec |\n    +--------------------------------+-----------+-----------+-----------+-----------+--------------------------------------------------+-+----------+----------+\n    |datetime (builtin)              |205 nsec   |198 nsec   |178 nsec   |N/A        |2.8x                                              |…|N/A       |N/A       |\n    +--------------------------------+-----------+-----------+-----------+-----------+--------------------------------------------------+-+----------+----------+\n    |pendulum                        |251 nsec   |259 nsec   |251 nsec   |262 nsec   |3.4x                                              |…|264 nsec  |264 nsec  |\n    +--------------------------------+-----------+-----------+-----------+-----------+--------------------------------------------------+-+----------+----------+\n    |udatetime                       |684 nsec   |700 nsec   |646 nsec   |684 nsec   |9.3x                                              |…|688 nsec  |676 nsec  |\n    +--------------------------------+-----------+-----------+-----------+-----------+--------------------------------------------------+-+----------+----------+\n    |str2date                        |5.95 usec  |4.34 usec  |4.11 usec  |4.58 usec  |80.5x                                             |…|4.6 usec  |4.82 usec |\n    +--------------------------------+-----------+-----------+-----------+-----------+--------------------------------------------------+-+----------+----------+\n    |iso8601                         |7.68 usec  |8.56 usec  |7.62 usec  |7.99 usec  |103.9x                                            |…|7.83 usec |8.16 usec |\n    +--------------------------------+-----------+-----------+-----------+-----------+--------------------------------------------------+-+----------+----------+\n    |isodate                         |7.77 usec  |8.53 usec  |7.54 usec  |7.88 usec  |105.0x                                            |…|8.12 usec |8.4 usec  |\n    +--------------------------------+-----------+-----------+-----------+-----------+--------------------------------------------------+-+----------+----------+\n    |iso8601utils                    |N/A        |N/A        |N/A        |N/A        |152.2x                                            |…|14.1 usec |14.6 usec |\n    +--------------------------------+-----------+-----------+-----------+-----------+--------------------------------------------------+-+----------+----------+\n    |zulu                            |17.8 usec  |16.9 usec  |15.7 usec  |17.3 usec  |241.3x                                            |…|17.3 usec |17.6 usec |\n    +--------------------------------+-----------+-----------+-----------+-----------+--------------------------------------------------+-+----------+----------+\n    |aniso8601                       |18 usec    |18.7 usec  |16.4 usec  |21.5 usec  |243.1x                                            |…|22.5 usec |22.8 usec |\n    +--------------------------------+-----------+-----------+-----------+-----------+--------------------------------------------------+-+----------+----------+\n    |PySO8601                        |18.3 usec  |16.6 usec  |14.3 usec  |15.8 usec  |247.5x                                            |…|16.2 usec |16.4 usec |\n    +--------------------------------+-----------+-----------+-----------+-----------+--------------------------------------------------+-+----------+----------+\n    |maya                            |46.2 usec  |N/A        |41 usec    |47.5 usec  |625.0x                                            |…|45.2 usec |47 usec   |\n    +--------------------------------+-----------+-----------+-----------+-----------+--------------------------------------------------+-+----------+----------+\n    |python-dateutil                 |47.1 usec  |48.2 usec  |47.1 usec  |57.3 usec  |636.5x                                            |…|60.4 usec |58.9 usec |\n    +--------------------------------+-----------+-----------+-----------+-----------+--------------------------------------------------+-+----------+----------+\n    |arrow                           |57.7 usec  |53.8 usec  |50.8 usec  |60.2 usec  |780.2x                                            |…|59.4 usec |60.1 usec |\n    +--------------------------------+-----------+-----------+-----------+-----------+--------------------------------------------------+-+----------+----------+\n    |metomi-isodatetime              |876 usec   |823 usec   |795 usec   |1.09 msec  |11846.4x                                          |…|1.09 msec |1.13 msec |\n    +--------------------------------+-----------+-----------+-----------+-----------+--------------------------------------------------+-+----------+----------+\n    |moment                          |❌         |❌         |❌         |❌         |2070678.8x                                        |…|❌        |❌        |\n    +--------------------------------+-----------+-----------+-----------+-----------+--------------------------------------------------+-+----------+----------+\n\nciso8601 takes 73.9 nsec, which is **2.8x faster than datetime (builtin)**, the next fastest Python 3.13 parser in this comparison.\n\n.. \u003c/include:benchmark_with_time_zone.rst\u003e\n\n.. \u003cinclude:benchmark_module_versions.rst\u003e\n\nTested on Linux 6.11.5-orbstack-00280-g96d99c92a42b using the following modules:\n\n.. code:: python\n\n  aniso8601==9.0.1\n  arrow==1.3.0\n  backports.datetime_fromisoformat==2.0.2\n  ciso8601==2.3.1\n  iso8601==2.1.0\n  iso8601utils==0.1.2\n  isodate==0.7.2\n  maya==0.6.1\n  metomi-isodatetime==1!3.1.0\n  moment==0.12.1\n  pendulum==3.0.0\n  PySO8601==0.2.0\n  python-dateutil==2.9.0.post0\n  str2date==0.905\n  udatetime==0.0.17\n  zulu==2.0.1\n\n.. \u003c/include:benchmark_module_versions.rst\u003e\n\nFor full benchmarking details (or to run the benchmark yourself), see `benchmarking/README.rst`_\n\n.. _`benchmarking/README.rst`: https://github.com/closeio/ciso8601/blob/master/benchmarking/README.rst\n\nSupported subset of ISO 8601\n----------------------------\n\n.. |datetime.fromisoformat| replace:: ``datetime.fromisoformat``\n.. _datetime.fromisoformat: https://docs.python.org/3/library/datetime.html#datetime.datetime.fromisoformat\n\n``ciso8601`` only supports a subset of ISO 8601, but supports a superset of what is supported by Python itself (|datetime.fromisoformat|_), and supports the entirety of the `RFC 3339`_ specification.\n\nDate formats\n^^^^^^^^^^^^\n\nThe following date formats are supported:\n\n.. table::\n   :widths: auto\n\n   ============================= ============== ==================\n   Format                        Example        Supported\n   ============================= ============== ==================\n   ``YYYY-MM-DD`` (extended)     ``2018-04-29`` ✅\n   ``YYYY-MM`` (extended)        ``2018-04``    ✅\n   ``YYYYMMDD`` (basic)          ``20180429``   ✅\n   ``YYYY-Www-D`` (week date)    ``2009-W01-1`` ✅\n   ``YYYY-Www`` (week date)      ``2009-W01``   ✅\n   ``YYYYWwwD`` (week date)      ``2009W011``   ✅\n   ``YYYYWww`` (week date)       ``2009W01``    ✅\n   ``YYYY-DDD`` (ordinal date)   ``1981-095``   ✅\n   ``YYYYDDD`` (ordinal date)    ``1981095``    ✅\n   ============================= ============== ==================\n\nUncommon ISO 8601 date formats are not supported:\n\n.. table::\n   :widths: auto\n\n   ============================= ============== ==================\n   Format                        Example        Supported\n   ============================= ============== ==================\n   ``--MM-DD`` (omitted year)    ``--04-29``    ❌\n   ``--MMDD`` (omitted year)     ``--0429``     ❌\n   ``±YYYYY-MM`` (\u003e4 digit year) ``+10000-04``  ❌\n   ``+YYYY-MM`` (leading +)      ``+2018-04``   ❌\n   ``-YYYY-MM`` (negative -)     ``-2018-04``   ❌\n   ============================= ============== ==================\n\nTime formats\n^^^^^^^^^^^^\n\nTimes are optional and are separated from the date by the letter ``T``.\n\nConsistent with `RFC 3339`__, ``ciso8601`` also allows either a space character, or a lower-case ``t``, to be used instead of a ``T``.\n\n__ https://stackoverflow.com/questions/522251/whats-the-difference-between-iso-8601-and-rfc-3339-date-formats\n\nThe following time formats are supported:\n\n.. table::\n   :widths: auto\n\n   =================================== =================== ==============\n   Format                              Example             Supported\n   =================================== =================== ==============\n   ``hh``                              ``11``              ✅\n   ``hhmm``                            ``1130``            ✅\n   ``hh:mm``                           ``11:30``           ✅\n   ``hhmmss``                          ``113059``          ✅\n   ``hh:mm:ss``                        ``11:30:59``        ✅\n   ``hhmmss.ssssss``                   ``113059.123456``   ✅\n   ``hh:mm:ss.ssssss``                 ``11:30:59.123456`` ✅\n   ``hhmmss,ssssss``                   ``113059,123456``   ✅\n   ``hh:mm:ss,ssssss``                 ``11:30:59,123456`` ✅\n   Midnight (special case)             ``24:00:00``        ✅\n   ``hh.hhh`` (fractional hours)       ``11.5``            ❌\n   ``hh:mm.mmm`` (fractional minutes)  ``11:30.5``         ❌\n   =================================== =================== ==============\n\n**Note:** Python datetime objects only have microsecond precision (6 digits). Any additional precision will be truncated.\n\nTime zone information\n^^^^^^^^^^^^^^^^^^^^^\n\nTime zone information may be provided in one of the following formats:\n\n.. table::\n   :widths: auto\n\n   ========== ========== ===========\n   Format     Example    Supported\n   ========== ========== ===========\n   ``Z``      ``Z``      ✅\n   ``z``      ``z``      ✅\n   ``±hh``    ``+11``    ✅\n   ``±hhmm``  ``+1130``  ✅\n   ``±hh:mm`` ``+11:30`` ✅\n   ========== ========== ===========\n\nWhile the ISO 8601 specification allows the use of MINUS SIGN (U+2212) in the time zone separator, ``ciso8601`` only supports the use of the HYPHEN-MINUS (U+002D) character.\n\nConsistent with `RFC 3339`_, ``ciso8601`` also allows a lower-case ``z`` to be used instead of a ``Z``.\n\nStrict RFC 3339 parsing\n-----------------------\n\n``ciso8601`` parses ISO 8601 datetimes, which can be thought of as a superset of `RFC 3339`_ (`roughly`_). In cases where you might want strict RFC 3339 parsing, ``ciso8601`` offers a ``parse_rfc3339`` method, which behaves in a similar manner to ``parse_datetime``:\n\n.. _roughly: https://stackoverflow.com/questions/522251/whats-the-difference-between-iso-8601-and-rfc-3339-date-formats\n\n``parse_rfc3339(dt: String): datetime`` is a function that takes a string and either:\n\n* Returns a properly parsed Python datetime, **if and only if** the **entire** string conforms to RFC 3339.\n* Raises a ``ValueError`` with a description of the reason why the string doesn't conform to RFC 3339.\n\nIgnoring time zone information while parsing\n--------------------------------------------\n\nIt takes more time to parse timestamps with time zone information, especially if they're not in UTC. However, there are times when you don't care about time zone information, and wish to produce naive datetimes instead.\nFor example, if you are certain that your program will only parse timestamps from a single time zone, you might want to strip the time zone information and only output naive datetimes.\n\nIn these limited cases, there is a second function provided.\n``parse_datetime_as_naive`` will ignore any time zone information it finds and, as a result, is faster for timestamps containing time zone information.\n\n.. code:: python\n\n  In [1]: import ciso8601\n\n  In [2]: ciso8601.parse_datetime_as_naive('2014-12-05T12:30:45.123456-05:30')\n  Out[2]: datetime.datetime(2014, 12, 5, 12, 30, 45, 123456)\n\nNOTE: ``parse_datetime_as_naive`` is only useful in the case where your timestamps have time zone information, but you want to ignore it. This is somewhat unusual.\nIf your timestamps don't have time zone information (i.e. are naive), simply use ``parse_datetime``. It is just as fast.\n","funding_links":[],"categories":["Python"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloseio%2Fciso8601","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcloseio%2Fciso8601","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcloseio%2Fciso8601/lists"}