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.0.tar.gz
(4.6 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.0.tar.gz.
File metadata
- Download URL: snowflake_tool-2.0.0.tar.gz
- Upload date:
- Size: 4.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
406f1a702e6f1b6dbfd20654417190c25d06ed66cdedcd40500be7f430877d68
|
|
| MD5 |
8c4a44922b35702b1b74fb8baa2336ab
|
|
| BLAKE2b-256 |
5e289cd72e149ca565141629c2026f5f9670683a911f3335383da805a05fd5ae
|
File details
Details for the file snowflake_tool-2.0.0-py3-none-any.whl.
File metadata
- Download URL: snowflake_tool-2.0.0-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 |
753b8e0958a3aeea4c30cbd90a3e361a93cda96d53c194187c61e9627f743b03
|
|
| MD5 |
409df499bd9c9e0514c99601af5d2e74
|
|
| BLAKE2b-256 |
1878139708731bf7b07dfde52b7c6643c7dd8b69dce01eb78f59bbd4172ffd06
|