Skip to main content

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

Install

pip install snowflake-tool

Usage

from snowflake import Snowflake

gen = Snowflake(1)
for i in range(int(1e5)):
    print(next(gen.g()))

Of course, you could also generate one id by generator:

from snowflake import Snowflake

gen = Snowflake(1)
print(gen.gen_id())

Reference:

  1. twitter-archive/snowflake: Snowflake is a network service for generating unique ID numbers at high scale with some simple guarantees. (github.com)
  2. bwmarrin/snowflake: A simple to use Go (golang) package to generate or parse Twitter snowflake IDs (github.com)
  3. Snowflake ID - Wikipedia

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.3.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

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

snowflake_tool-2.0.3-py3-none-any.whl (4.9 kB view details)

Uploaded Python 3

File details

Details for the file snowflake_tool-2.0.3.tar.gz.

File metadata

  • Download URL: snowflake_tool-2.0.3.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for snowflake_tool-2.0.3.tar.gz
Algorithm Hash digest
SHA256 4d8a98435206124c2700ca3f3d0de7186e662b6baa0b3d96fb0d41539bb6c7c6
MD5 d0c4270ab1a2d833b154a2c79aa35150
BLAKE2b-256 063f8d08581e89fa374867b0d2facc458bd8d814a87cb2f9dc542400803c7c94

See more details on using hashes here.

File details

Details for the file snowflake_tool-2.0.3-py3-none-any.whl.

File metadata

  • Download URL: snowflake_tool-2.0.3-py3-none-any.whl
  • Upload date:
  • Size: 4.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.7

File hashes

Hashes for snowflake_tool-2.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1cbec3ca191c199739c7c7b6034639ab378baa2816619592549b233bce0e8ef5
MD5 8f3f69dd5d8f4cf86801a3e9b4f028fa
BLAKE2b-256 f3357869978e17f1624cb9a053148cb6404612cc48e4531c2db2aba99c06b516

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