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}")
# Generated snowflake: 17359567945990144
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file flakemaker-1.0.0.post1.tar.gz.
File metadata
- Download URL: flakemaker-1.0.0.post1.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dfb5696dce20200ca904febea188f5d361ef5aa254caa5dec7173fc9710660db
|
|
| MD5 |
39f8f4d8158577510d1e6b2cee14a08e
|
|
| BLAKE2b-256 |
544db0e820e5af3b60f43752c410368eb650e3c256021e3060a392d74358f1fa
|
File details
Details for the file flakemaker-1.0.0.post1-py3-none-any.whl.
File metadata
- Download URL: flakemaker-1.0.0.post1-py3-none-any.whl
- Upload date:
- Size: 3.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
84c58f3a17ec590e4f33bc618c949848b39d1f2c7d5e6562435d90f5f8b0c4f6
|
|
| MD5 |
abe2459e22105f858e96cbfda3a06702
|
|
| BLAKE2b-256 |
1669b87d1d45b2291f30b0dc4f8bc8a49acaeb7787c8834e92c51f2b0a861899
|