Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

snowflake-util

A Python library for generating Discord, Twitter, Instagram and custom snowflakes.

A snowflake is a unique identifier for a resource that includes, among other things, a timestamp of when such a snowflake was created. Snowflakes are used by Twitter, Discord or Instagram. They were created by Twitter in 2010.

Developed by TheMultii (c) 2022-present

Installing

# Linux/macOS

python3 -m pip install -U snowflake-util



# Windows

py -3 -m pip install -U snowflake-util

Examples of How To Use

Creating a custom snowflake

from datetime import datetime

import snowflake



config = snowflake.SnowflakeConfig(

    epoch=snowflake.Epoch.discord, # or Unix timestamp in milliseconds with maximum length of 13 digits.

    leading_bit=False,

    timestamp_length=42,

    param1_length=5,

    param2_length=5,

    sequence_length=12

)



SnowClass = snowflake.Snowflake(config)



custom_snowflake = SnowClass.generate_snowflake(param1=11, param2=3, sequence=753)

custom_snowflake_TS = SnowClass.generate_snowflake(param1=14, param2=9, sequence=357, date=datetime(2021, 8, 8, 8, 8, 0, 0))



print(custom_snowflake, SnowClass.parse_snowflake(custom_snowflake))

print(custom_snowflake_TS, SnowClass.parse_snowflake(custom_snowflake_TS))

Creating a Discord snowflake

SnowClass = snowflake.Snowflake()



discord_snowflake = SnowClass.generate_discord_snowflake(worker=5, process=5, sequence=222, date=datetime(2022, 1, 1, 16, 15, 0, 0))



print(discord_snowflake, SnowClass.parse_discord_snowflake(discord_snowflake))

Creating a Twitter snowflake

SnowClass = snowflake.Snowflake()



twitter_snowflake = SnowClass.generate_twitter_snowflake(machine=333, sequence=666, date=datetime(2022, 1, 1, 16, 15, 0, 0))



print(twitter_snowflake, SnowClass.parse_twitter_snowflake(twitter_snowflake))

Creating an Instagram snowflake

SnowClass = snowflake.Snowflake()



instagram_snowflake = SnowClass.generate_instagram_snowflake(shard=1605, sequence=420, date=datetime(2020, 6, 11, 8 ,13))



print(instagram_snowflake, SnowClass.parse_instagram_snowflake(instagram_snowflake))

IMPORTANT INFO:

  • Generating any snowflakes does not require sending the date as an argument - the snowflake will be generated based on the current time.

  • snowflake.SnowflakeConfig is not required if you want to use any of the ready-made templates for generating/reading snowflakes (Twitter, Discord, Instagram)

  • You can edit and read the current configuration settings using the Snowflake.set_config() and Snowflake.get_config() methods.

  • All methods are documented in the code.

  • The leading_bit is used by Twitter to generate snowflakes.

  • For custom configuration, sum of leading_bit, timestamp_length, param1_length, param2_length, sequence_length must be exactly 64.

  • Snowflakes can only be generated for dates that are after the set epoch.

  • There must be a 64-bit representation for each snowflake.

References

License

MIT

Release files for snowflake-util 1.0.0b7

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-util 1.0.0b7
File Size Uploaded
snowflake_util-1.0.0b7.tar.gz 8.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for snowflake-util 1.0.0b7
File Interpreter ABI Platform
snowflake_util-1.0.0b7-py3-none-any.whl Python 3 none any Details

Total release size: 18.2 kB

Release files / snowflake_util-1.0.0b7.tar.gz

Download URL snowflake_util-1.0.0b7.tar.gz
Size 8.1 kB
Tags Source
SHA-256 checksum
How to use checksums
9af24b34f834b2631ef65c738d021decc24ab9e49a8347647d17e57f7b53165a
BLAKE2b-256 checksum
How to use checksums
217767f6825cd881429eb758daa5bfaf1e583c742968e5d2fc922f3640bd681f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.7

Release files / snowflake_util-1.0.0b7-py3-none-any.whl

Download URL snowflake_util-1.0.0b7-py3-none-any.whl
Size 10.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
d9bb2af433f42c57fefeeaf399ebf8e4ee691fccb8dfb82b86104b44fda0fb4f
BLAKE2b-256 checksum
How to use checksums
97802b882a1ffdaab00ee3bd4afa71878e38f49cd3a5f72c53a30342f1b918f8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.7
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