Skip to main content

Short Snowflake ID

A lightweight Python library that bridges the gap between distributed Snowflake IDs and clean, compact, time-sortable strings.

Overview

Standard database auto-increment counters leak business data (like total record counts) and look clumsy in web links. On the other hand, traditional random UUIDs solve privacy issues but wreck database indexing because they are completely chaotic and un-sortable.

ShortSnowflakeID combines the best of both worlds:

  1. Distributed & Monotonic: Generates 63-bit integers containing a millisecond timestamp, a node ID, and an inner sequence counter.
  2. Human & URL-Friendly: Translates those numbers into fixed-length strings using a custom, unambiguous alphabet (stripping out easily confused glyphs like l, 1, I, O, and 0).
  3. Chronologically Sorted: Because the underlying numbers strictly increase over time, the resulting strings sort naturally in databases just like standard numbers.

Key Features

  • Time-Sortable: Ideal for database primary keys, cursors, and chronological feeds.
  • Cluster-Ready: Safely run across multiple servers or worker threads using unique node_id configurations.
  • Embedded Metadata: Extract the exact creation timestamp down to the millisecond straight from the ID, without hitting the database.
  • No Heavy Dependencies: Pure, clean Python implementation.

Installation

Ensure you are running Python 3.6+ and include the module in your project source tree.

Usage

Just import it in your project like so:

>>> import shortsnowflakeid

Generating a Short ID

>>> shortsnowflakeid.random()
'3e26HbYeqZh'

Getting the Raw Integer

If your database prefers working with numerical IDs under the hood:

>>> shortsnowflakeid.random_int()
590696153977196544

Encoding and Decoding

Seamlessly convert back and forth between raw integers and concise strings:

>>> s = shortsnowflakeid.encode(590696153977196544)
>>> s
'3e27EC89Wjx'
>>> shortsnowflakeid.decode(s) == 590696153977196544
True

Reading the Timestamp

Retrieve the precise creation moment (in Unix milliseconds) from any short string or raw integer:

>>> shortsnowflakeid.decode_timestamp_ms(s)
1786540537712

Customization

You can easily tailor the generator to your needs by adjusting the node ID, custom epoch, or alphabet set during initialization:

custom_generator = shortsnowflakeid.ShortSnowflakeID(
    node_id=3,
    epoch=1645707600000,
    alphabet="23456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz"
)

License

shortsnowflakeid is distributed under the BSD license.

Metadata

Release files for shortsnowflakeid 1.0.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 shortsnowflakeid 1.0.0
File Size Uploaded
shortsnowflakeid-1.0.0.tar.gz 6.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for shortsnowflakeid 1.0.0
File Interpreter ABI Platform
shortsnowflakeid-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 12.5 kB

Release files / shortsnowflakeid-1.0.0.tar.gz

Download URL shortsnowflakeid-1.0.0.tar.gz
Size 6.6 kB
Tags Source
SHA-256 checksum
How to use checksums
14c19a76f7cd9b9e0a8a13dd8e1da953b4caae6ecc1b3b40b957af9f0960c90b
BLAKE2b-256 checksum
How to use checksums
8d664faa288d8ac2a0ae80d108d1001b34c4552edb3e5f3ab2083512a1db373f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Release files / shortsnowflakeid-1.0.0-py3-none-any.whl

Download URL shortsnowflakeid-1.0.0-py3-none-any.whl
Size 5.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
610c22c3619a39287046683815fe93fa7ef9cf35af05cdd9365abf5628af6465
BLAKE2b-256 checksum
How to use checksums
f70c7303f8ac2e81e337e9f236b39b4f031b6d8309364f677cde49fec3a8c89c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.5

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

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