uu2nano


Nameuu2nano JSON
Version 1.0 PyPI version JSON
download
home_page
SummaryConversion tool from UUID to nanoid and vice versa
upload_time2023-07-24 12:17:32
maintainer
docs_urlNone
author
requires_python>=3.7
license
keywords uuid nanoid
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # uu2nano

Simple tool for converting well-known [UUID](https://datatracker.ietf.org/doc/html/rfc4122)
format (36 chars) to [nanoid](https://pypi.org/project/nanoid/) format (21 chars).


## Details of conversion

UUID is basically a 128-bit number. Some of those bits contain metadata including
the version, on which the content of the remaining bits depends.
For example, for UUIDv4 all 122 unspecified bits should contain random entropy.
But more interesting that regardless of version, 2 bits in each UUID are fixed.
That is why any UUID of any version could be encoded as 126 bits.

UUIDs are encoded in hex format (4 bit per symbol) and 4 hyphens are added
as separators, which leads to 128/4 + 4 = 36 characters in the string representation.

For example: `492b6acb-05c7-4914-b139-253070a085e9`

Nanoid is encoded using 64 URL-safe symbols (`A-Za-z0-9_-`) which makes possible
to store 6 bits of information per symbol. To store 126 UUID bits, only 
126 / 6 = 21 characters are used in the string representation.

For example: `ggHEMKl5gfh2T7h-KC6lD`


## Usage

Convert one to another:

```python
import uuid
from uu2nano import fix_uuid, nanoid_to_uuid, uuid_to_nanoid

uu = uuid.uuid4()
nano = uuid_to_nanoid(uu)
assert uu == nanoid_to_uuid(nano)
```

If you receive not compliant UUIDs from third parties, there is a chance that eventually
two reserved fixed bits could be wrong. In this case `uuid_to_nanoid` will fail:

```python

@app.post
def find_book(uu: uuid.UUID):
    nano = uuid_to_nanoid(uu)

AssertionError: Wrong mark bits. Use fix_uuid() for true random input
```

If this happens you can use `fix_uuid` function to get a valid UUID.
Please note that in this case UUID will be changed, so you have to save
new alias somewhere (in UUID, int, or nanoid format).

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "uu2nano",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "uuid,nanoid",
    "author": "",
    "author_email": "Aleksandr Karpinskii <homm86@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/a2/71/edebac00fd2ca1454d28b6286a34f7c8647a4ed8a350a5b876d90625b4ae/uu2nano-1.0.tar.gz",
    "platform": null,
    "description": "# uu2nano\n\nSimple tool for converting well-known [UUID](https://datatracker.ietf.org/doc/html/rfc4122)\nformat (36 chars) to [nanoid](https://pypi.org/project/nanoid/) format (21 chars).\n\n\n## Details of conversion\n\nUUID is basically a 128-bit number. Some of those bits contain metadata including\nthe version, on which the content of the remaining bits depends.\nFor example, for UUIDv4 all 122 unspecified bits should contain random entropy.\nBut more interesting that regardless of version, 2 bits in each UUID are fixed.\nThat is why any UUID of any version could be encoded as 126 bits.\n\nUUIDs are encoded in hex format (4 bit per symbol) and 4 hyphens are added\nas separators, which leads to 128/4 + 4 = 36 characters in the string representation.\n\nFor example: `492b6acb-05c7-4914-b139-253070a085e9`\n\nNanoid is encoded using 64 URL-safe symbols (`A-Za-z0-9_-`) which makes possible\nto store 6 bits of information per symbol. To store 126 UUID bits, only \n126 / 6 = 21 characters are used in the string representation.\n\nFor example: `ggHEMKl5gfh2T7h-KC6lD`\n\n\n## Usage\n\nConvert one to another:\n\n```python\nimport uuid\nfrom uu2nano import fix_uuid, nanoid_to_uuid, uuid_to_nanoid\n\nuu = uuid.uuid4()\nnano = uuid_to_nanoid(uu)\nassert uu == nanoid_to_uuid(nano)\n```\n\nIf you receive not compliant UUIDs from third parties, there is a chance that eventually\ntwo reserved fixed bits could be wrong. In this case `uuid_to_nanoid` will fail:\n\n```python\n\n@app.post\ndef find_book(uu: uuid.UUID):\n    nano = uuid_to_nanoid(uu)\n\nAssertionError: Wrong mark bits. Use fix_uuid() for true random input\n```\n\nIf this happens you can use `fix_uuid` function to get a valid UUID.\nPlease note that in this case UUID will be changed, so you have to save\nnew alias somewhere (in UUID, int, or nanoid format).\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "Conversion tool from UUID to nanoid and vice versa",
    "version": "1.0",
    "project_urls": {
        "Repository": "https://github.com/homm/uu2nano"
    },
    "split_keywords": [
        "uuid",
        "nanoid"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f7d42f41a75426514143a99c7b55cbda75ddd75c2e790e127e558b0d205aaa7d",
                "md5": "d1eaf775b817f7d00c9b620553559a46",
                "sha256": "1532da1435ad24d391a921498ff1813dc73f08f974b86f5843f78ffc4cfe799b"
            },
            "downloads": -1,
            "filename": "uu2nano-1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "d1eaf775b817f7d00c9b620553559a46",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 2670,
            "upload_time": "2023-07-24T12:10:26",
            "upload_time_iso_8601": "2023-07-24T12:10:26.969177Z",
            "url": "https://files.pythonhosted.org/packages/f7/d4/2f41a75426514143a99c7b55cbda75ddd75c2e790e127e558b0d205aaa7d/uu2nano-1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a271edebac00fd2ca1454d28b6286a34f7c8647a4ed8a350a5b876d90625b4ae",
                "md5": "ac76f54f50c1dcd039e1b6b19092c61c",
                "sha256": "71697370cdf92195cae3b77a5674cb1e6253056e361f42c646f7f688d3119e72"
            },
            "downloads": -1,
            "filename": "uu2nano-1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "ac76f54f50c1dcd039e1b6b19092c61c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 2586,
            "upload_time": "2023-07-24T12:17:32",
            "upload_time_iso_8601": "2023-07-24T12:17:32.547988Z",
            "url": "https://files.pythonhosted.org/packages/a2/71/edebac00fd2ca1454d28b6286a34f7c8647a4ed8a350a5b876d90625b4ae/uu2nano-1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-07-24 12:17:32",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "homm",
    "github_project": "uu2nano",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "uu2nano"
}
        
Elapsed time: 0.09290s