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.2.tar.gz (4.3 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.2-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: snowflake_tool-2.0.2.tar.gz
  • Upload date:
  • Size: 4.3 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.2.tar.gz
Algorithm Hash digest
SHA256 870e80d899498d3ce8ce92ee35302354b00ea0dd313be952e2b2639ca18baaa4
MD5 634f7ea2e286b34729f927ce7e83ba9d
BLAKE2b-256 1e89374731ec01231a65a6d22f19c63cf09be73c9e64684dfca0049d0ce9f1de

See more details on using hashes here.

File details

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

File metadata

  • Download URL: snowflake_tool-2.0.2-py3-none-any.whl
  • Upload date:
  • Size: 4.8 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 797e43105a4f24b9aac719b252deaf7a35db88bbffbacc97cda4055b93109c45
MD5 a37abdbb2856b296693eb9b735a11679
BLAKE2b-256 8deece83ffd086106cbd1f7ac32cfbf6f9ac871568564e7ed675300992ac0683

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