Sqids Python

0.5.2 · active · verified Thu Apr 16

Sqids (pronounced "squids") is a small, active, and community-maintained Python library that generates short, unique, and URL-safe IDs from non-negative numbers. It's commonly used for link shortening, generating IDs for public URLs or internal systems, and decoding for quicker database lookups. The current version is 0.5.2, and it follows a regular release cadence with ongoing development across various language ports.

Common errors

Warnings

Install

Imports

Quickstart

Initializes the Sqids encoder/decoder and demonstrates basic encoding and decoding of numbers, as well as enforcing a minimum ID length.

from sqids import Sqids

sqids = Sqids()

# Encode numbers into a Sqid
numbers_to_encode = [1, 2, 3]
id = sqids.encode(numbers_to_encode)
print(f"Encoded ID: {id}") # Example: 86Rf07

# Decode a Sqid back into numbers
decoded_numbers = sqids.decode(id)
print(f"Decoded numbers: {decoded_numbers}") # Example: [1, 2, 3]

# Enforce a minimum length for the ID
sqids_min_length = Sqids(min_length=10)
id_padded = sqids_min_length.encode([1, 2, 3])
print(f"Padded ID: {id_padded}") # Example: 86Rf07xd4z

view raw JSON →