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:
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)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
add584a433c2096c17b2a48ceae231dceaff8a06f4cde00a2c4700c1629e1da8
|
|
| MD5 |
0e7cb3891ac3cb6a7fc70c7e2e73e6fc
|
|
| BLAKE2b-256 |
76c9238c4dce59b0739b1988187ca762d74d1482e3484439d9fbc9459cc14af3
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1fec102f8d176aea63160b5074dff3030c52d4958fd5e3f6bde65de7c379ee27
|
|
| MD5 |
907c75ba450dd590369d566ff690115a
|
|
| BLAKE2b-256 |
57eedfb61f5e68124a321ad52a12f3de2740e74b3b8cc724c43a3f924120e535
|