Skip to main content

Snowflake ID Toolkit - Generate distributed unique 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 (coming soon)

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 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.2.0.tar.gz (6.6 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.2.0-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for snowflake_id_toolkit-0.2.0.tar.gz
Algorithm Hash digest
SHA256 1fc72c5d32b5aafe3c76ba28f2de890bedb8c9278a9caf1952bbdd16899ca11d
MD5 7b2e00bb9f6dafb1b9837bb039bbe1cf
BLAKE2b-256 d79ef39815f25cc0b33e9bdc9360817efac83b3b488c183318d9c15cb575fa31

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for snowflake_id_toolkit-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1644e91d7915fae684dc1bada7d1f2794aa3db369b97465b27c6e9205ce023f9
MD5 117cfec16fc7b9d864cdca42b6fcbbe0
BLAKE2b-256 035b257e39a600be68b74c3a7dc952e17b57a16fb65bca7298c8eea7f119275a

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