uuid7


Nameuuid7 JSON
Version 0.1.0 PyPI version JSON
download
home_pagehttps://github.com/stevesimmons/uuid7
SummaryUUID version 7, generating time-sorted UUIDs with 200ns time resolution and 48 bits of randomness
upload_time2021-12-29 01:38:21
maintainer
docs_urlNone
authorStephen Simmons
requires_python>=3.7
licenseMIT license
keywords uuid7
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            uuid7 - time-sortable UUIDs
===========================

This module implements the version 7 UUIDs, proposed by Peabody and Davis in
https://www.ietf.org/id/draft-peabody-dispatch-new-uuid-format-02.html
as an extension to RFC4122.

Version 7 has the nice characteristic that the start of a UUID encodes
the time with a chronological sort order and potentially ~50ns time
resolution, while the end of the UUID includes sufficient random bits to
ensure consecutive UUIDs will remain unique.

Implementation notes
--------------------

The 128 bits in the UUID are allocated as follows: 

* 36 bits of whole seconds
* 24 bits of fractional seconds, giving approx 50ns resolution
* 14 bits of sequential counter, if called repeatedly in same time tick
* 48 bits of randomness

plus, at locations defined by RFC4122, 4 bits for the uuid version (0b111) and 2 bits for the uuid variant (0b10).

.. code:: text

                0                   1                   2                   3
                0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       t1      |                 unixts (secs since epoch)                     |
               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       t2/t3   |unixts |  frac secs (12 bits)  |  ver  |  frac secs (12 bits)  |
               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       t4/rand |var|       seq (14 bits)       |          rand (16 bits)       |
               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
       rand    |                          rand (32 bits)                       |
               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Indicative timings:

* `uuid.uuid4()` - 2.4us
* `uuid7()` - 3.7us
* `uuid7(as_type='int')` - 1.6us
* `uuid7(as_type='str')` - 2.5us

Installation
------------

.. code:: bash

   > pip install uuid7

Usage
-----

.. code:: ipython

   >>> from uuid_extensions import uuid7, uuid7str
   >>> uuid7()
   UUID('061cb26a-54b8-7a52-8000-2124e7041024')

   >>> uuid7(0)
   UUID('00000000-0000-0000-0000-00000000000')

   >>> for fmt in ('bytes', 'hex', 'int', 'str', 'uuid', None):
   ...     print(fmt, repr(uuid7(as_type=fmt)))
   bytes b'\x06\x1c\xb8\xfe\x0f\x0b|9\x80\x00\tjt\x85\xb3\xbb'
   hex '061cb8fe0f0b7c3980011863b956b758'
   int 8124504378724980906989670469352026642
   str '061cb8fe-0f0b-7c39-8003-d44a7ee0bdf6'
   uuid UUID('061cb8fe-0f0b-7c39-8004-0489578299f6')
   None UUID('061cb8fe-0f0f-7df2-8000-afd57c2bf446')

   >>> uuid7str() # Shorthand for uuid7(as_type='str')
   '061cb26a-54b8-7a52-8000-2124e7041024'

Licence
-------

-  Free software: MIT license


=======
History
=======

0.1.0 (2021-12-28)
------------------

* First release on PyPI.



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/stevesimmons/uuid7",
    "name": "uuid7",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "uuid7",
    "author": "Stephen Simmons",
    "author_email": "mail@stevesimmons.com",
    "download_url": "https://files.pythonhosted.org/packages/5c/19/7472bd526591e2192926247109dbf78692e709d3e56775792fec877a7720/uuid7-0.1.0.tar.gz",
    "platform": "",
    "description": "uuid7 - time-sortable UUIDs\n===========================\n\nThis module implements the version 7 UUIDs, proposed by Peabody and Davis in\nhttps://www.ietf.org/id/draft-peabody-dispatch-new-uuid-format-02.html\nas an extension to RFC4122.\n\nVersion 7 has the nice characteristic that the start of a UUID encodes\nthe time with a chronological sort order and potentially ~50ns time\nresolution, while the end of the UUID includes sufficient random bits to\nensure consecutive UUIDs will remain unique.\n\nImplementation notes\n--------------------\n\nThe 128 bits in the UUID are allocated as follows: \n\n* 36 bits of whole seconds\n* 24 bits of fractional seconds, giving approx 50ns resolution\n* 14 bits of sequential counter, if called repeatedly in same time tick\n* 48 bits of randomness\n\nplus, at locations defined by RFC4122, 4 bits for the uuid version (0b111) and 2 bits for the uuid variant (0b10).\n\n.. code:: text\n\n                0                   1                   2                   3\n                0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1\n               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n       t1      |                 unixts (secs since epoch)                     |\n               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n       t2/t3   |unixts |  frac secs (12 bits)  |  ver  |  frac secs (12 bits)  |\n               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n       t4/rand |var|       seq (14 bits)       |          rand (16 bits)       |\n               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n       rand    |                          rand (32 bits)                       |\n               +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+\n\nIndicative timings:\n\n* `uuid.uuid4()` - 2.4us\n* `uuid7()` - 3.7us\n* `uuid7(as_type='int')` - 1.6us\n* `uuid7(as_type='str')` - 2.5us\n\nInstallation\n------------\n\n.. code:: bash\n\n   > pip install uuid7\n\nUsage\n-----\n\n.. code:: ipython\n\n   >>> from uuid_extensions import uuid7, uuid7str\n   >>> uuid7()\n   UUID('061cb26a-54b8-7a52-8000-2124e7041024')\n\n   >>> uuid7(0)\n   UUID('00000000-0000-0000-0000-00000000000')\n\n   >>> for fmt in ('bytes', 'hex', 'int', 'str', 'uuid', None):\n   ...     print(fmt, repr(uuid7(as_type=fmt)))\n   bytes b'\\x06\\x1c\\xb8\\xfe\\x0f\\x0b|9\\x80\\x00\\tjt\\x85\\xb3\\xbb'\n   hex '061cb8fe0f0b7c3980011863b956b758'\n   int 8124504378724980906989670469352026642\n   str '061cb8fe-0f0b-7c39-8003-d44a7ee0bdf6'\n   uuid UUID('061cb8fe-0f0b-7c39-8004-0489578299f6')\n   None UUID('061cb8fe-0f0f-7df2-8000-afd57c2bf446')\n\n   >>> uuid7str() # Shorthand for uuid7(as_type='str')\n   '061cb26a-54b8-7a52-8000-2124e7041024'\n\nLicence\n-------\n\n-  Free software: MIT license\n\n\n=======\nHistory\n=======\n\n0.1.0 (2021-12-28)\n------------------\n\n* First release on PyPI.\n\n\n",
    "bugtrack_url": null,
    "license": "MIT license",
    "summary": "UUID version 7, generating time-sorted UUIDs with 200ns time resolution and 48 bits of randomness",
    "version": "0.1.0",
    "project_urls": {
        "Homepage": "https://github.com/stevesimmons/uuid7"
    },
    "split_keywords": [
        "uuid7"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "b5778852f89a91453956582a85024d80ad96f30a41fed4c2b3dce0c9f12ecc7e",
                "md5": "263df74dde5d0ef582f58a139ab6a734",
                "sha256": "5e259bb63c8cb4aded5927ff41b444a80d0c7124e8a0ced7cf44efa1f5cccf61"
            },
            "downloads": -1,
            "filename": "uuid7-0.1.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "263df74dde5d0ef582f58a139ab6a734",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.7",
            "size": 7477,
            "upload_time": "2021-12-29T01:38:20",
            "upload_time_iso_8601": "2021-12-29T01:38:20.418074Z",
            "url": "https://files.pythonhosted.org/packages/b5/77/8852f89a91453956582a85024d80ad96f30a41fed4c2b3dce0c9f12ecc7e/uuid7-0.1.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5c197472bd526591e2192926247109dbf78692e709d3e56775792fec877a7720",
                "md5": "32e035254ff14d34cfd15000c2637295",
                "sha256": "8c57aa32ee7456d3cc68c95c4530bc571646defac01895cfc73545449894a63c"
            },
            "downloads": -1,
            "filename": "uuid7-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "32e035254ff14d34cfd15000c2637295",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 14052,
            "upload_time": "2021-12-29T01:38:21",
            "upload_time_iso_8601": "2021-12-29T01:38:21.897028Z",
            "url": "https://files.pythonhosted.org/packages/5c/19/7472bd526591e2192926247109dbf78692e709d3e56775792fec877a7720/uuid7-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2021-12-29 01:38:21",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "stevesimmons",
    "github_project": "uuid7",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "uuid7"
}
        
Elapsed time: 0.23476s