Create snowflakes with encoded data in them.
Project description
flakemaker
The flakemaker
library offers a straightforward approach to generating unique, time-based identifiers similar to Discord's snowflake IDs, but repurposing the worker and process IDs into a generalized "parameter".
Features
- Generates 64-bit snowflake IDs.
- Customizable epoch.
- Includes a user-defined parameter at snowflake generation. Note that this replaces the worker and process ids!
Quickstart
Generating a Snowflake
To generate a snowflake, create an instance of SnowflakeGenerator
and call the generate
method with your parameter.
from flakemaker import SnowflakeGenerator
generator = SnowflakeGenerator() # you can put a time here in milliseconds since 1970
snowflake = generator.generate(42) # or any value from 0-1023
print(f"Generated snowflake: {snowflake}")
Parsing a Snowflake
To parse an existing snowflake and extract its creation time and parameter, use the parse
method.
dt, parameter = generator.parse(snowflake)
print(f"Timestamp: {dt}, Parameter: {parameter}")
# Timestamp: datetime.datetime(2024, 2, 17, 13, 49, 13, 466377), Parameter: 42
This method returns the timestamp of the snowflake as a datetime
object in UTC and the parameter encoded within the snowflake.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
flakemaker-1.0.0.tar.gz
(3.6 kB
view hashes)
Built Distribution
Close
Hashes for flakemaker-1.0.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51495b2b51dca89c08b88ef7c20d19600dfc77837b94deac8b2e81933d4765e4 |
|
MD5 | 02cb448dd938b21925085781580621e4 |
|
BLAKE2b-256 | 2e1379ba8eefa6680f23c8446646cd4cc30d083a2a8e90359c87f87e830d84d9 |