short-unique-id

Tiny, dependency-free Snowflake-style & short random ID generator for Python 3

https://github.com/purushot14/short-unique-id

Science Score: 44.0%

This score indicates how likely this project is to be science-related based on various indicators:

  • CITATION.cff file
    Found CITATION.cff file
  • codemeta.json file
    Found codemeta.json file
  • .zenodo.json file
    Found .zenodo.json file
  • DOI references
  • Academic publication links
  • Academic email domains
  • Institutional organization owner
  • JOSS paper metadata
  • Scientific vocabulary similarity
    Low similarity (10.2%) to scientific vocabulary

Keywords

id-generator python shortid snowflake-id uuid
Last synced: 6 months ago · JSON representation ·

Repository

Tiny, dependency-free Snowflake-style & short random ID generator for Python 3

Basic Info
Statistics
  • Stars: 2
  • Watchers: 0
  • Forks: 0
  • Open Issues: 0
  • Releases: 0
Topics
id-generator python shortid snowflake-id uuid
Created about 7 years ago · Last pushed 9 months ago
Metadata Files
Readme License Citation

README.md

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 random 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, millisecond-precision, monotonic & k-sortable
  • 12-char random IDs – base-62 tokens for URLs, files, IoT messages, …
  • Stateless & thread-safe – no Redis, no database round-trips
  • Zero dependencies – pure-Python, install in seconds
  • Python 3.9 → 3.13 – fully typed, passes pytest & Ruff
  • MIT licensed

🚀 Install

bash pip install short-unique-id

Or grab the latest dev build:

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


⚡ Quick-start

```python import shortuniqueid as suid

12-character, URL-safe string (random)

slug = suid.generateshortid() print(slug) # → "aZ8Ft1jK2L3q"

Ordered, 64-bit Snowflake integer

snowflake = suid.getnextsnowflake_id() print(snowflake) # → 489683493715968001 ```

Need higher entropy or longer range? Pass a custom mult (time multiplier):

python 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 | 12 | | 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: int = 10_000) → str | 12-char base‑62 string | Random but unique within the given time bucket. | mult – bucket size (↑ = ↑ entropy) | | get_next_snowflake_id(mult: int = 10_000) → int | 64-bit int | Monotonic, timestamp‑encoded Snowflake ID. | mult – ticks per ms |


📚 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:

bash poetry add --dev pre-commit

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

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


📝 Changelog

See CHANGELOG. Notable releases:

| Version | Date | Highlights | |-----------|------------|-------------------------------------------------------------| | 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.

Owner

  • Name: Purushothaman Kumaravel
  • Login: Purushot14
  • Kind: user
  • Company: Kissflow inc

Citation (CITATION.cff)

cff-version: 1.2.0
message: "If you use this library, please cite it as below."
title: "short-unique-id: Snowflake‑style and short random ID generator for Python"
version: "0.2.1"
doi: "10.5281/zenodo.1234567"
date-released: 2025-05-19
url: "https://github.com/Purushot14/short-unique-id"
repository-code: "https://github.com/Purushot14/short-unique-id"
license: "MIT"
authors:
  - family-names: "Purushothaman"
    given-names: "Prakash"
    email: "prakash.purushot@gmail.com"
    affiliation: "Independent open‑source developer"
    orcid: "0000-0002-1234-5678"
keywords:
  - shortid
  - snowflake
  - uuid
  - unique-id
  - python

GitHub Events

Total
  • Release event: 2
  • Watch event: 2
  • Delete event: 1
  • Push event: 10
  • Create event: 3
Last Year
  • Release event: 2
  • Watch event: 2
  • Delete event: 1
  • Push event: 10
  • Create event: 3

Packages

  • Total packages: 1
  • Total downloads:
    • pypi 874 last-month
  • Total dependent packages: 0
  • Total dependent repositories: 0
  • Total versions: 3
  • Total maintainers: 1
pypi.org: short-unique-id

Tiny, dependency-free Snowflake-style and random short ID generator for Python.

  • Versions: 3
  • Dependent Packages: 0
  • Dependent Repositories: 0
  • Downloads: 874 Last month
Rankings
Dependent packages count: 6.6%
Average: 29.0%
Forks count: 30.5%
Dependent repos count: 30.6%
Downloads: 38.1%
Stargazers count: 39.1%
Maintainers (1)
Last synced: 6 months ago

Dependencies

poetry.lock pypi
  • colorama 0.4.6
  • exceptiongroup 1.3.0
  • iniconfig 2.1.0
  • packaging 25.0
  • pluggy 1.6.0
  • pytest 7.4.4
  • ruff 0.3.7
  • setuptools 80.7.1
  • tomli 2.2.1
  • typing-extensions 4.13.2
pyproject.toml pypi
  • pytest ^7.4.0 develop
  • ruff ^0.3.0 develop
  • setuptools 80.7.1 develop
  • python >=3.8
setup.py pypi