Skip to main content

Simple snowflake id generator

Project description

Snowflake-tool

Snowflake tool is a Python library that implements the Snowflake algorithm and is used to generate Snowflake ID.

The default Twitter format shown below.

+------------------------------------------------------------------------------+
| 1 Bit Unused | 41 Bit Timestamp |  10 Bit Machine ID  |   12 Bit Sequence ID |
+------------------------------------------------------------------------------+

Performance

Bench(1e5)

===================================================== test session starts ====================================================== 
platform win32 -- Python 3.13.7, pytest-8.4.2, pluggy-1.6.0
rootdir: D:\Code\snowflake-tool
configfile: pyproject.toml
collected 2 items                                                                                                                

test\test_snowflake.py
2025-09-17 15:41:12,307 - test_generate - INFO - Time bench=100000: 114 ms

.
2025-09-17 15:41:12,333 - test_generate - INFO - Time bench=100000: 24 ms

.

====================================================== 2 passed in 0.16s ======================================================= 

Bench(1e6)

===================================================== test session starts ====================================================== 
platform win32 -- Python 3.13.7, pytest-8.4.2, pluggy-1.6.0
rootdir: D:\Code\snowflake-tool
configfile: pyproject.toml
collected 2 items                                                                                                                

test\test_snowflake.py
2025-09-17 15:41:24,754 - test_generate - INFO - Time bench=1000000: 1169 ms

.
2025-09-17 15:41:25,177 - test_generate - INFO - Time bench=1000000: 413 ms

.

====================================================== 2 passed in 1.66s ======================================================= 

Install

pip install snowflake-tool

Usage

from snowflake import Snowflake

gen = Snowflake(1)
for i in range(int(1e5)):
    print(next(gen))

Of course, you could also generate one id by generator:

from snowflake import Snowflake

gen = Snowflake(1)
print(gen.generate())

Reference:

  1. twitter-archive/snowflake: Snowflake is a network service for generating unique ID numbers at high scale with some simple guarantees. (github.com)
  2. bwmarrin/snowflake: A simple to use Go (golang) package to generate or parse Twitter snowflake IDs (github.com)
  3. Snowflake ID - Wikipedia

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_tool-2.0.1.tar.gz (4.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_tool-2.0.1-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file snowflake_tool-2.0.1.tar.gz.

File metadata

  • Download URL: snowflake_tool-2.0.1.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for snowflake_tool-2.0.1.tar.gz
Algorithm Hash digest
SHA256 add584a433c2096c17b2a48ceae231dceaff8a06f4cde00a2c4700c1629e1da8
MD5 0e7cb3891ac3cb6a7fc70c7e2e73e6fc
BLAKE2b-256 76c9238c4dce59b0739b1988187ca762d74d1482e3484439d9fbc9459cc14af3

See more details on using hashes here.

File details

Details for the file snowflake_tool-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: snowflake_tool-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for snowflake_tool-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1fec102f8d176aea63160b5074dff3030c52d4958fd5e3f6bde65de7c379ee27
MD5 907c75ba450dd590369d566ff690115a
BLAKE2b-256 57eedfb61f5e68124a321ad52a12f3de2740e74b3b8cc724c43a3f924120e535

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