Skip to main content

Snowflake

The Snowflake generator done right.

See here for additional information.

Requirements

Python 3.8 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 = }")
print(f"{int(sf) = }")

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)
int(sf) = 856165981072306191

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
...

Release files for snowflake-id 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for snowflake-id 1.0.2
File Size Uploaded
snowflake_id-1.0.2.tar.gz 4.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for snowflake-id 1.0.2
File Interpreter ABI Platform
snowflake_id-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 9.3 kB

Release files / snowflake_id-1.0.2.tar.gz

Download URL snowflake_id-1.0.2.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
4a4cd49508599aaa16488311f4b9121e9ac3bac57edff3e9f71b1d79086dbfe8
BLAKE2b-256 checksum
How to use checksums
7ad091bd3d2e54ea849e8c4e73681ef75c1c93f37a8c9f0627b1553522267e08
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.14.0 CPython/3.12.3 Linux/6.5.0-1018-azure

Release files / snowflake_id-1.0.2-py3-none-any.whl

Download URL snowflake_id-1.0.2-py3-none-any.whl
Size 4.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c3142752ed334b9d4632739a704461d13e97aa6fa71b65d5329829b4b5cc058c
BLAKE2b-256 checksum
How to use checksums
41a4ee0bdba1d1e98db21166381559d0061d752bbf66af2dd1cbbe4c2afdc4fa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.14.0 CPython/3.12.3 Linux/6.5.0-1018-azure

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.1

2 release files

1.0.0

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page