Snowflake
The Snowflake generator done right.
See here for additional information.
Requirements
Python 3.7 and above. No additional dependencies.
Installation
pip install snowflake-id
Usage
Using generator
from snowflake import SnowflakeGenerator
gen = SnowflakeGenerator(42)
for i in range(100):
val = next(gen)
print(val)
Output:
6820698575169822721
6820698575169822722
6820698575169822723
6820698575174017024
6820698575174017025
...
Parse snowflake id
from snowflake import Snowflake
sf = Snowflake.parse(856165981072306191, 1288834974657)
print(f"{sf.timestamp = }")
print(f"{sf.instance = }")
print(f"{sf.epoch = }")
print(f"{sf.seq = }")
print(f"{sf.seconds = }")
print(f"{sf.milliseconds = }")
print(f"{sf.datetime = }")
Output:
sf.timestamp = 204125876682
sf.instance = 363
sf.epoch = 1288834974657
sf.seq = 15
sf.seconds = 1492960851.339
sf.milliseconds = 1492960851339
sf.datetime = datetime.datetime(2017, 4, 23, 15, 20, 51, 339000)
Load generator state
from snowflake import SnowflakeGenerator, Snowflake
sf = Snowflake.parse(856165981072306191, 1288834974657)
gen = SnowflakeGenerator.from_snowflake(sf)
for i in range(100):
val = next(gen)
print(val)
Output:
1414934653136449536
1414934653136449537
1414934653136449538
1414934653136449539
1414934653136449540
...
Metadata
Release files for snowflake-id 0.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| snowflake-id-0.0.2.tar.gz | 3.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| snowflake_id-0.0.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.1 kB
Release files / snowflake-id-0.0.2.tar.gz
| Download URL | snowflake-id-0.0.2.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
87728871afbb00ffcd99b047a7ffff2d22d26ffe2ba59ab5426ab963924bc33c
|
|
BLAKE2b-256 checksum How to use checksums |
e3831c070c12242ed821ace15a470dc647f5b8b5d8da3616f688de5805847d71
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.10
|
Release files / snowflake_id-0.0.2-py3-none-any.whl
| Download URL | snowflake_id-0.0.2-py3-none-any.whl |
|---|---|
| Size | 4.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b2a6d6ee0dcfa4c7546ed8a9c97e17a6d500a932cb26256a27e7aad6aff78b49
|
|
BLAKE2b-256 checksum How to use checksums |
78bbfa95a3693b6b59077368980065e76f56230a44b94794ccd51b7b037a2c88
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.4.1 importlib_metadata/4.6.1 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.2 CPython/3.8.10
|