EasyFlake is a Python package for generating 64-bit IDs similar to Snowflake or Sonyflake.
Project description
EasyFlake
EasyFlake is a Python package for generating 64-bit IDs similar to Snowflake or Sonyflake. It provides a simple way to generate unique and sortable IDs that can be used as primary keys in databases, message queue messages, or other distributed systems.
Installation
Install the latest version of EasyFlake using pip:
pip install easyflake
Usage
To use EasyFlake, simply create an instance of the EasyFlake
class, passing in a unique node ID:
from easyflake import EasyFlake
ef = EasyFlake(node_id=1)
print(ef.get_id())
The get_id()
method generates the next ID by the current timestamp. You can customize the number of bits used for the node ID and sequence ID parts, as well as the epoch timestamp and time scale.
ef = EasyFlake(node_id=0, node_id_bits=4, sequence_bits=6)
print(ef.get_id())
Arguments
node_id
(int): A unique ID for the current node. This ID should be between 0 and (2 ^ node_id_bits) - 1. If no argument is given, a random value is assigned to the node ID.node_id_bits
(int): The maximum number of bits used to represent the node ID. This argument defaults to 8 / max node ID is 255.sequence_bits
(int): The maximum number of bits used to represent the sequence number. This argument defaults to 8 / max sequence number is 255.epoch
(float): A timestamp used as a reference when generating the timestamp section of the ID. This argument defaults to 1675859040 (2023-02-08T12:24:00Z).time_scale
(int): The number of decimal places used to represent the timestamp. This argument defaults to 3 (milliseconds).
Contributing
See the contributing guide.
License
This project is licensed under the MIT License - see the LICENSE file for details.
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
File details
Details for the file easyflake-0.1.0.tar.gz
.
File metadata
- Download URL: easyflake-0.1.0.tar.gz
- Upload date:
- Size: 12.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.8.16 Linux/5.15.0-1033-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee2c688ce518e5cc0d46afe2a9f3301350aa1bc0a212f36e36549dbc089038a3 |
|
MD5 | 09cad19d8d5d1e2ffff7c6ed046d8c4a |
|
BLAKE2b-256 | 897151b8592ea98d54e5376a6aaac817ffa24817b64ddd0e03d916157a7a6511 |
File details
Details for the file easyflake-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: easyflake-0.1.0-py3-none-any.whl
- Upload date:
- Size: 16.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.3.2 CPython/3.8.16 Linux/5.15.0-1033-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd7bd490927e778d8354e28fd8c6b12927bbb1dd8d1f2a14bb6ff6c12cef4605 |
|
MD5 | ef7246aed64962adc863c542cc29b9c4 |
|
BLAKE2b-256 | 2b3abe5b8e72487b2c561fd2645655450e004417fa3d0953957fd9bba3944ed9 |