Skip to main content

EasyFlake is a Python package for generating 64-bit IDs similar to Snowflake or Sonyflake.

Project description

EasyFlake

Test passing codecov PyPI PyPI - Python Version License

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, where node_id_bits is an optional argument that defaults to 8.
  • node_id_bits (int, optional): The maximum number of bits used to represent the node ID. This argument defaults to 8.
  • sequence_bits (int, optional): The maximum number of bits used to represent the sequence number. This argument defaults to 10.
  • epoch (float, optional): 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, optional): The number of decimal places used to represent the timestamp. This argument defaults to 3(milliseconds).

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

easyflake-0.0.3.tar.gz (5.9 kB view details)

Uploaded Source

Built Distribution

easyflake-0.0.3-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file easyflake-0.0.3.tar.gz.

File metadata

  • Download URL: easyflake-0.0.3.tar.gz
  • Upload date:
  • Size: 5.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.10.6 Linux/5.15.0-60-generic

File hashes

Hashes for easyflake-0.0.3.tar.gz
Algorithm Hash digest
SHA256 5f4bb65318c1593852064097f81cd3fe28f3de1cb9b5968d36a6de8eabc5ab29
MD5 3d684b45d2104acd98ccb27d60993295
BLAKE2b-256 1af99df1dcb6e219a7609eb816ca55e74167eb2b68b3326484c7f8023973f7f3

See more details on using hashes here.

File details

Details for the file easyflake-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: easyflake-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.3.1 CPython/3.10.6 Linux/5.15.0-60-generic

File hashes

Hashes for easyflake-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 7a8b1224003118d18ad24e21370c1090bae67c1ec4c8fe1ab303a5749942f278
MD5 028f115edf51f0dbb9271eaa6f1654f7
BLAKE2b-256 d11112b79ebac8374efeaa75d300ab38825d2460fd432a452d58c3834085802b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page