Skip to main content

Generate YouTube-like ids from numbers.

Project description

Sqids Python

Github Actions

Sqids (pronounced "squids") is a small library that lets you generate YouTube-looking IDs from numbers. It's good for link shortening, fast & URL-safe ID generation and decoding back into numbers for quicker database lookups.

Getting started

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

pip install sqids

Import the constructor from the sqids module:

from sqids import Sqids
sqids = Sqids()

Examples

Simple encode & decode:

sqids = Sqids()
id = sqids.encode([1, 2, 3]) # "8QRLaD"
numbers = sqids.decode(id) # [1, 2, 3]

Randomize IDs by providing a custom alphabet:

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

Enforce a minimum length for IDs:

sqids = Sqids(min_length=10)
id = sqids.encode([1, 2, 3]) # "75JT1cd0dL"
numbers = sqids.decode(id) # [1, 2, 3]

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

sqids = Sqids(blocklist={"word1", "word2"})
id = sqids.encode([1, 2, 3]) # "8QRLaD"
numbers = sqids.decode(id) # [1, 2, 3]

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sqids-0.2.0.tar.gz (9.1 kB view hashes)

Uploaded Source

Built Distribution

sqids-0.2.0-py3-none-any.whl (6.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page