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

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

from snowflake import Snowflake

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

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-1.0.0.tar.gz (4.0 kB view hashes)

Uploaded Source

Built Distribution

snowflake_tool-1.0.0-py3-none-any.whl (4.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page