Skip to content

Snowflake tool is a Python library that implements the Snowflake algorithm and is used to generate Snowflake ID.

License

Notifications You must be signed in to change notification settings

785Coder/snowflake-tool

Repository files navigation

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

About

Snowflake tool is a Python library that implements the Snowflake algorithm and is used to generate Snowflake ID.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages