Skip to main content

The Snowflake generator done right

Project description

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

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_id-1.0.1.tar.gz (4.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

snowflake_id-1.0.1-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file snowflake_id-1.0.1.tar.gz.

File metadata

  • Download URL: snowflake_id-1.0.1.tar.gz
  • Upload date:
  • Size: 4.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.12.4 CPython/3.12.2

File hashes

Hashes for snowflake_id-1.0.1.tar.gz
Algorithm Hash digest
SHA256 452dc13659b08b052505854e7870bb49306deddc3450d88d5ec77b9ffb3b6cc8
MD5 4e07fbedeea550ef839ca56928e93ebd
BLAKE2b-256 e220c9fa158a7d9eb47f174685b4378581ec8794ef35ff9a463e76480db8f48e

See more details on using hashes here.

File details

Details for the file snowflake_id-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: snowflake_id-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: pdm/2.12.4 CPython/3.12.2

File hashes

Hashes for snowflake_id-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3f544377089ba74fa8c0af55fafee39794132b8ee6325f750e21b550c7a21aac
MD5 74553499ee05d9ce6d5b1e76d682fe95
BLAKE2b-256 ba0b3a73daebd776d416e2ff9e281659ad37c3b92a2d7bdfb926781b88f30cb8

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