sqids


Namesqids JSON
Version 0.4.1 PyPI version JSON
download
home_page
SummaryGenerate YouTube-like ids from numbers.
upload_time2023-11-13 08:03:49
maintainer
docs_urlNone
author
requires_python>=3.6
licenseMIT License Copyright (c) 2023-present Sqids maintainers. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords sqids encode generate ids hashids
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # [Sqids Python](https://sqids.org/python)

[![PyPI package](https://badge.fury.io/py/sqids.svg)](https://pypi.org/project/sqids/)
[![Github Actions](https://img.shields.io/github/actions/workflow/status/sqids/sqids-python/tests.yml)](https://github.com/sqids/sqids-python/actions)
[![Downloads](https://img.shields.io/pypi/dm/sqids)](https://pypi.org/project/sqids/)

[Sqids](https://sqids.org/python) (*pronounced "squids"*) is a small library that lets you **generate unique IDs from numbers**. It's good for link shortening, fast & URL-safe ID generation and decoding back into numbers for quicker database lookups.

Features:

- **Encode multiple numbers** - generate short IDs from one or several non-negative numbers
- **Quick decoding** - easily decode IDs back into numbers
- **Unique IDs** - generate unique IDs by shuffling the alphabet once
- **ID padding** - provide minimum length to make IDs more uniform
- **URL safe** - auto-generated IDs do not contain common profanity
- **Randomized output** - Sequential input provides nonconsecutive IDs
- **Many implementations** - Support for [40+ programming languages](https://sqids.org/)

## 🧰 Use-cases

Good for:

- Generating IDs for public URLs (eg: link shortening)
- Generating IDs for internal systems (eg: event tracking)
- Decoding for quicker database lookups (eg: by primary keys)

Not good for:

- Sensitive data (this is not an encryption library)
- User IDs (can be decoded revealing user count)

## 🚀 Getting started

Install the package from PyPI, e. g. with pip:

```bash
pip install sqids
```

Import the `Sqids` class from the `sqids` package:

```python
from sqids import Sqids
sqids = Sqids()
```

## 👩‍💻 Examples

Simple encode & decode:

```python
sqids = Sqids()
id = sqids.encode([1, 2, 3]) # "86Rf07"
numbers = sqids.decode(id) # [1, 2, 3]
```

> **Note**
> 🚧 Because of the algorithm's design, **multiple IDs can decode back into the same sequence of numbers**. If it's important to your design that IDs are canonical, you have to manually re-encode decoded numbers and check that the generated ID matches.

Enforce a *minimum* length for IDs:

```python
sqids = Sqids(min_length=10)
id = sqids.encode([1, 2, 3]) # "86Rf07xd4z"
numbers = sqids.decode(id) # [1, 2, 3]
```

Randomize IDs by providing a custom alphabet:

```python
sqids = Sqids(alphabet="FxnXM1kBN6cuhsAvjW3Co7l2RePyY8DwaU04Tzt9fHQrqSVKdpimLGIJOgb5ZE")
id = sqids.encode([1, 2, 3]) # "B4aajs"
numbers = sqids.decode(id) # [1, 2, 3]
```

Prevent specific words from appearing anywhere in the auto-generated IDs:

```python
sqids = Sqids(blocklist=["86Rf07"])
id = sqids.encode([1, 2, 3]) # "se8ojk"
numbers = sqids.decode(id) # [1, 2, 3]
```

## 📝 License

[MIT](LICENSE)

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "sqids",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.6",
    "maintainer_email": "",
    "keywords": "sqids,encode,generate,ids,hashids",
    "author": "",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/cb/b5/1e6d184f616edcd73d4402ed2b83563bd61ed98ce48946155dd0ac4d4785/sqids-0.4.1.tar.gz",
    "platform": null,
    "description": "# [Sqids Python](https://sqids.org/python)\n\n[![PyPI package](https://badge.fury.io/py/sqids.svg)](https://pypi.org/project/sqids/)\n[![Github Actions](https://img.shields.io/github/actions/workflow/status/sqids/sqids-python/tests.yml)](https://github.com/sqids/sqids-python/actions)\n[![Downloads](https://img.shields.io/pypi/dm/sqids)](https://pypi.org/project/sqids/)\n\n[Sqids](https://sqids.org/python) (*pronounced \"squids\"*) is a small library that lets you **generate unique IDs from numbers**. It's good for link shortening, fast & URL-safe ID generation and decoding back into numbers for quicker database lookups.\n\nFeatures:\n\n- **Encode multiple numbers** - generate short IDs from one or several non-negative numbers\n- **Quick decoding** - easily decode IDs back into numbers\n- **Unique IDs** - generate unique IDs by shuffling the alphabet once\n- **ID padding** - provide minimum length to make IDs more uniform\n- **URL safe** - auto-generated IDs do not contain common profanity\n- **Randomized output** - Sequential input provides nonconsecutive IDs\n- **Many implementations** - Support for [40+ programming languages](https://sqids.org/)\n\n## \ud83e\uddf0 Use-cases\n\nGood for:\n\n- Generating IDs for public URLs (eg: link shortening)\n- Generating IDs for internal systems (eg: event tracking)\n- Decoding for quicker database lookups (eg: by primary keys)\n\nNot good for:\n\n- Sensitive data (this is not an encryption library)\n- User IDs (can be decoded revealing user count)\n\n## \ud83d\ude80 Getting started\n\nInstall the package from PyPI, e. g. with pip:\n\n```bash\npip install sqids\n```\n\nImport the `Sqids` class from the `sqids` package:\n\n```python\nfrom sqids import Sqids\nsqids = Sqids()\n```\n\n## \ud83d\udc69\u200d\ud83d\udcbb Examples\n\nSimple encode & decode:\n\n```python\nsqids = Sqids()\nid = sqids.encode([1, 2, 3]) # \"86Rf07\"\nnumbers = sqids.decode(id) # [1, 2, 3]\n```\n\n> **Note**\n> \ud83d\udea7 Because of the algorithm's design, **multiple IDs can decode back into the same sequence of numbers**. If it's important to your design that IDs are canonical, you have to manually re-encode decoded numbers and check that the generated ID matches.\n\nEnforce a *minimum* length for IDs:\n\n```python\nsqids = Sqids(min_length=10)\nid = sqids.encode([1, 2, 3]) # \"86Rf07xd4z\"\nnumbers = sqids.decode(id) # [1, 2, 3]\n```\n\nRandomize IDs by providing a custom alphabet:\n\n```python\nsqids = Sqids(alphabet=\"FxnXM1kBN6cuhsAvjW3Co7l2RePyY8DwaU04Tzt9fHQrqSVKdpimLGIJOgb5ZE\")\nid = sqids.encode([1, 2, 3]) # \"B4aajs\"\nnumbers = sqids.decode(id) # [1, 2, 3]\n```\n\nPrevent specific words from appearing anywhere in the auto-generated IDs:\n\n```python\nsqids = Sqids(blocklist=[\"86Rf07\"])\nid = sqids.encode([1, 2, 3]) # \"se8ojk\"\nnumbers = sqids.decode(id) # [1, 2, 3]\n```\n\n## \ud83d\udcdd License\n\n[MIT](LICENSE)\n",
    "bugtrack_url": null,
    "license": "MIT License  Copyright (c) 2023-present Sqids maintainers.  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.  THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ",
    "summary": "Generate YouTube-like ids from numbers.",
    "version": "0.4.1",
    "project_urls": {
        "Homepage": "https://sqids.org/python"
    },
    "split_keywords": [
        "sqids",
        "encode",
        "generate",
        "ids",
        "hashids"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3e480f5d1aff8f431c3128bea0f5201fe5ae4562a57655faf17245d0673dd5a9",
                "md5": "a896b5417df6d469f6c21ab236de13a4",
                "sha256": "fe48319ae1a7ea4faca77920f454fcf2946bbca540a468a98d979ba490d195bd"
            },
            "downloads": -1,
            "filename": "sqids-0.4.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a896b5417df6d469f6c21ab236de13a4",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6",
            "size": 7788,
            "upload_time": "2023-11-13T08:03:47",
            "upload_time_iso_8601": "2023-11-13T08:03:47.546213Z",
            "url": "https://files.pythonhosted.org/packages/3e/48/0f5d1aff8f431c3128bea0f5201fe5ae4562a57655faf17245d0673dd5a9/sqids-0.4.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "cbb51e6d184f616edcd73d4402ed2b83563bd61ed98ce48946155dd0ac4d4785",
                "md5": "1b134fbf682ac2383de966e099fced2a",
                "sha256": "ffc3fbfef63491bee8b940a98065388345dbefb06d49e415b7a9e475ca200f9d"
            },
            "downloads": -1,
            "filename": "sqids-0.4.1.tar.gz",
            "has_sig": false,
            "md5_digest": "1b134fbf682ac2383de966e099fced2a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6",
            "size": 14060,
            "upload_time": "2023-11-13T08:03:49",
            "upload_time_iso_8601": "2023-11-13T08:03:49.328420Z",
            "url": "https://files.pythonhosted.org/packages/cb/b5/1e6d184f616edcd73d4402ed2b83563bd61ed98ce48946155dd0ac4d4785/sqids-0.4.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-11-13 08:03:49",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "sqids"
}
        
Elapsed time: 0.18858s