Skip to main content

Python toolkit for generating Twitter Snowflake & Sonyflake IDs

Project description

snowflake-id-toolkit

A Python toolkit for generating snowflake-like unique IDs.

Supported Implementations

  • Twitter Snowflake - 64-bit IDs with ~69 years of timestamps, 1024 nodes, 4096 IDs per millisecond per node
  • Instagram Snowflake - 64-bit IDs with ~69 years of timestamps, 8192 shards, 1024 IDs per millisecond per shard
  • Sony Sonyflake - 64-bit IDs with ~174 years of timestamps, 256 nodes, 65,536 IDs per 10ms per node

Installation

pip install snowflake-id-toolkit

Usage

from snowflake_id_toolkit.twitter import TwitterSnowflakeIDGenerator

generator = TwitterSnowflakeIDGenerator(
    node_id=0,
    epoch=1288834974657  # Twitter's default epoch
)
snowflake_id = generator.generate_next_id()

Comparison with Other ID Strategies

Feature Snowflake UUIDv4 UUIDv7 Auto-increment
Size 64 bits 128 bits 128 bits 32-64 bits
Sortable by time
Distributed generation
No coordination needed ⚠️
DB Index-friendly ⚠️
Predictability Medium None Low High
Throughput 4,096,000/sec/node
(6,553,600 for Sonyflake)
Unlimited Unlimited DB-limited
Relative speed ~5.2x ~1.1x 1x (baseline) N/A (DB-bound)

When to Use

  • Snowflake: High-throughput distributed systems needing compact, sortable IDs
  • UUIDv4: When unpredictability matters, size doesn't, and no sorting needed
  • UUIDv7: Modern default choice when simplicity is key factor and 128 bits is acceptable
  • Auto-increment: Single-database apps where simplicity wins

License

The snowflake-id-toolkit is licensed under the MIT License. See the LICENSE file for more information.

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

snowflake_id_toolkit-0.4.0.tar.gz (8.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

snowflake_id_toolkit-0.4.0-py3-none-any.whl (12.7 kB view details)

Uploaded Python 3

File details

Details for the file snowflake_id_toolkit-0.4.0.tar.gz.

File metadata

File hashes

Hashes for snowflake_id_toolkit-0.4.0.tar.gz
Algorithm Hash digest
SHA256 cd446c58027a431d1bb26cd48eea89075d0cc08c1d2f665b9c3d59833d82fd88
MD5 dcee90c0ba0235b7730c88f359ef944e
BLAKE2b-256 19859ceeae84f4a1facd6efbfe42e632f4b92aecaf18b496a4e70a678fc5d28d

See more details on using hashes here.

File details

Details for the file snowflake_id_toolkit-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for snowflake_id_toolkit-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 cef676576cafd1f91af637da25f7efc3afba679e30e1098e303ffdf92f1151e1
MD5 573d28da2168b6b4d3ef0f990490a2d3
BLAKE2b-256 0a4da506ca46b4b5cb01a990f03e7065eec8c243b775bf5ebb7a976f5c6e52f9

See more details on using hashes here.

Supported by

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