Skip to main content

short-unique-id 🐍⚡️

PyPI Downloads CI License: MIT PyPI - Python Version PyPI - Wheel Lines of Code Code Style: Ruff Coverage GitHub Release Date PRs Welcome CodeQL pre-commit

Tiny, dependency-free Snowflake-style ordered IDs and ultra-short unique IDs for Python 3.9+

Need a sortable primary-key like Twitter’s Snowflake, or just a compact URL-safe slug? short-unique-id gives you both—without C extensions or heavy dependencies.


✨ Features

  • Ordered Snowflake IDs – 64-bit, monotonic & k-sortable (100 μs precision at default mult)
  • Short base-64 string IDs – compact, URL-safe tokens for URLs, files, IoT messages, …
  • Sortable or shuffled – ordered alphabet for lexicographic sort, or shuffled alphabet for opaque tokens
  • Stateless & thread-safe – no Redis, no database round-trips
  • Zero dependencies – pure-Python, install in seconds
  • Python 3.9 → 3.14 – fully typed, passes pytest & Ruff
  • MIT licensed

🚀 Install

pip install short-unique-id

Or grab the latest dev build:

pip install git+https://github.com/Purushot14/short-unique-id.git

⚡ Quick-start

import short_unique_id as suid

# URL-safe, lexicographically sortable string (default is_ordered=True)
slug = suid.generate_short_id()
print(slug)             # → "1vAo4-1g-1---"

# Opaque token using shuffled alphabet
token = suid.generate_short_id(is_ordered=False)
print(token)            # → "qZ8Ft1jK2L3R"

# Ordered, 64-bit Snowflake integer
snowflake = suid.get_next_snowflake_id()
print(snowflake)        # → 489683493715968001

Need higher precision or longer range? Pass a custom mult (ticks per second):

slug      = suid.generate_short_id(mult=1_000_000)
snowflake = suid.get_next_snowflake_id(mult=1_000_000)

🔬 Micro-benchmark†

Generator Mean time / 1 000 ids Bytes / id
short-unique-id 0.75 ms ~11–13
uuid.uuid4() 1.90 ms 36
ulid-py (ULID) 2.15 ms 26

† MacBook M3, Python 3.13, single thread, timeit.repeat 5 × 1000.


🛠️ API Reference

Function Returns Description Key Args
generate_short_id(mult=None, is_ordered=True) → str base‑64 string Snowflake ID encoded as a compact string. Sortable by default; pass is_ordered=False for an opaque token. mult – ticks per second (default 10 000); is_ordered – use ASCII-ordered alphabet
get_next_snowflake_id(mult=None) → int 64-bit int Monotonic, timestamp‑encoded Snowflake ID. mult – ticks per second (default 10 000)

📚 When to use it

  • Primary keys in distributed databases (fits in BIGINT)
  • Short share links or invite codes
  • File/folder names on S3 / GCS (lexicographic sort ≈ creation time)
  • Message IDs in event streams & IoT payloads
  • Anywhere you’d reach for UUIDs but want shorter or ordered IDs

🤝 Contributing

  1. git clone https://github.com/Purushot14/short-unique-id && cd short-unique-id
  2. poetry install – sets up venv & dev tools
  3. poetry run pytest – all green? start hacking!
  4. Run ruff check . --fix && ruff format . before PRs
  5. Open a PR – stars and issues welcome ⭐

🛡️ Pre-commit (via Poetry)

pre-commit

Make sure you’ve added pre-commit as a dev dependency:

poetry add --dev pre-commit

Set up the Git hook and run it against all files:

poetry run pre-commit install
poetry run pre-commit run --all-files

📝 Changelog

Notable releases:

Version Date Highlights
0.3.0 2026-03-27 Fix duplicate ID bug (bit-layout), base-64 encoding fix, Python 3.14 support, release CI/CD pipeline
0.2.1 2025-05-20 Python3.13 support added and Badges added on readme
0.2.0 2025-05-19 Repo rename, Poetry build, SEO README, classifiers & keywords
0.1.2 2018-11-25 Initial public release

🪪 License

Distributed under the MIT License © 2018–2025 Purushot14. See LICENSE.


Made with ❤️ for hackers who hate 36‑byte IDs.

Metadata

Release files for short-unique-id 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for short-unique-id 0.3.0
File Size Uploaded Provenance Actions
short_unique_id-0.3.0.tar.gz 5.9 kB With provenance Details for short_unique_id-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for short-unique-id 0.3.0
File Interpreter ABI Platform Actions
short_unique_id-0.3.0-py3-none-any.whl Python 3 none any Details for short_unique_id-0.3.0-py3-none-any.whl

Total release size: 12.5 kB

Release files / short_unique_id-0.3.0.tar.gz

Download URL short_unique_id-0.3.0.tar.gz
Size 5.9 kB
Tags Source
SHA-256 checksum
How to use checksums
8828a6193de10480b3cea50bbb6accabdb54af1c6a3dca96860a9a81ef5640d6
BLAKE2b-256 checksum
How to use checksums
3a1c0990555c387436b00ececd3895dcd6306bcad891b1d7749fff8d682f78b6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 27, 2026.

Transparency log

Release files / short_unique_id-0.3.0-py3-none-any.whl

Download URL short_unique_id-0.3.0-py3-none-any.whl
Size 6.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3d619fc4ca44c5be3dce409bbcc56281d8c88c1257b1f45cae469cbf51191d67
BLAKE2b-256 checksum
How to use checksums
064858f6286553a8f057e1e2723bc6870746b1e2330c2264906b741c8768ab3b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 27, 2026.

Transparency log

Security for short-unique-id 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for short_unique_id-0.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Mar 27, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page