easyflake


Nameeasyflake JSON
Version 0.3.1 PyPI version JSON
download
home_pagehttps://github.com/tsuperis/easyflake
SummaryEasyFlake is a Python package for generating 64-bit IDs similar to Snowflake or Sonyflake.
upload_time2023-03-10 12:07:30
maintainer
docs_urlNone
authorTakeru Furuse
requires_python>=3.8,<4.0
license
keywords snowflake sonyflake easyflake
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            # EasyFlake

[![Test passing](https://github.com/tsuperis/easyflake/actions/workflows/test.yml/badge.svg)](https://github.com/tsuperis/easyflake/actions/workflows/test.yml)
[![codecov](https://codecov.io/gh/tsuperis/easyflake/branch/main/graph/badge.svg?token=3TIHGMYN1G)](https://codecov.io/gh/tsuperis/easyflake)
[![PyPI](https://img.shields.io/pypi/v/easyflake)](https://pypi.org/project/easyflake/)
[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/easyflake)](https://pypi.org/project/easyflake/)
[![License](https://img.shields.io/github/license/tsuperis/easyflake)](https://github.com/tsuperis/easyflake/blob/main/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.

## Introduction

In a distributed system, it can be challenging to generate unique IDs for records that need to be stored or processed across multiple nodes. EasyFlake provides a way to generate IDs that are unique, sortable, and easy to work with.


## Use Cases

Here are some examples of use cases for EasyFlake:

* User account IDs: Generate unique IDs for user accounts that can be used across multiple servers or databases.
* Transaction IDs: Generate IDs for financial transactions that need to be processed across multiple systems.
* Order numbers: Generate unique order numbers that can be sorted by timestamp.

## Installation

Install the latest version of EasyFlake using pip:

```bash
pip install easyflake
```

## Usage

To use EasyFlake, simply create an instance of the `EasyFlake` class, passing in a unique node ID:

```python
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.

```python
ef = EasyFlake(node_id=0, node_id_bits=4, sequence_bits=6)
print(ef.get_id())
```

The components of the output ID are the sequence value, node ID, and timestamp, in order from the lower bits.

### Arguments

* `node_id` (int, [NodeIdPool](#nodeidpool)): A unique ID for the current node. This ID should be between 0 and (2 ^ node_id_bits) - 1.
* `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).

### API

#### `NodeIDPool`

This is a class that manages node IDs in a single-threaded or single-process environment. The default options provided are `GrpcNodeIdPool` and `FileNodeIdPool.` By inheriting from `BaseNodeIdPool`, you can also create your own custom node ID management.

##### `easyflake.FileNodeIdPool`

This is a file-based node ID management class. Care should be taken in distributed systems, as node IDs are managed by a single file.

###### Arguments

* `endpoint` (str): The path to the file where node IDs are recorded.
* `bits` (int): The maximum number of bits for node IDs.

##### `easyflake.GrpcNodeIdPool`

This is a gRPC-based node ID management class.
You can start a gRPC server using [`easyflake-cli grpc`](#easyflake-cli-grpc).  
However, it's important to note that the gRPC server can become a single point of failure in your system, so proper measures should be taken to ensure its availability.

###### Arguments

* `endpoint` (str): The address of the gRPC server.
* `bits` (int): The maximum number of bits for node IDs.

### Command

#### `easyflake-cli grpc`

This command starts a gRPC server for managing node IDs.

##### `Options`

* `-p`, `--port`: Specifies the port number of the gRPC server.
* `-d`, `--daemon`: Starts the server in daemon mode (not supported on Windows).
* `--pid-file`: Specifies the path to the PID file.

## Contributing

See the [contributing guide](https://github.com/tsuperis/easyflake/blob/main/CONTRIBUTING.md).

## License

This project is licensed under the MIT License - see the [LICENSE](https://github.com/tsuperis/easyflake/blob/main/LICENSE) file for details.

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/tsuperis/easyflake",
    "name": "easyflake",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8,<4.0",
    "maintainer_email": "",
    "keywords": "snowflake,sonyflake,easyflake",
    "author": "Takeru Furuse",
    "author_email": "tsuperis@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/47/5d/8dfb9cd065efe310e2f67237e367bc485400212d8574e0d19029307c223a/easyflake-0.3.1.tar.gz",
    "platform": null,
    "description": "# EasyFlake\n\n[![Test passing](https://github.com/tsuperis/easyflake/actions/workflows/test.yml/badge.svg)](https://github.com/tsuperis/easyflake/actions/workflows/test.yml)\n[![codecov](https://codecov.io/gh/tsuperis/easyflake/branch/main/graph/badge.svg?token=3TIHGMYN1G)](https://codecov.io/gh/tsuperis/easyflake)\n[![PyPI](https://img.shields.io/pypi/v/easyflake)](https://pypi.org/project/easyflake/)\n[![PyPI - Python Version](https://img.shields.io/pypi/pyversions/easyflake)](https://pypi.org/project/easyflake/)\n[![License](https://img.shields.io/github/license/tsuperis/easyflake)](https://github.com/tsuperis/easyflake/blob/main/LICENSE)\n\nEasyFlake 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.\n\n## Introduction\n\nIn a distributed system, it can be challenging to generate unique IDs for records that need to be stored or processed across multiple nodes. EasyFlake provides a way to generate IDs that are unique, sortable, and easy to work with.\n\n\n## Use Cases\n\nHere are some examples of use cases for EasyFlake:\n\n* User account IDs: Generate unique IDs for user accounts that can be used across multiple servers or databases.\n* Transaction IDs: Generate IDs for financial transactions that need to be processed across multiple systems.\n* Order numbers: Generate unique order numbers that can be sorted by timestamp.\n\n## Installation\n\nInstall the latest version of EasyFlake using pip:\n\n```bash\npip install easyflake\n```\n\n## Usage\n\nTo use EasyFlake, simply create an instance of the `EasyFlake` class, passing in a unique node ID:\n\n```python\nfrom easyflake import EasyFlake\n\nef = EasyFlake(node_id=1)\nprint(ef.get_id())\n```\n\nThe `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.\n\n```python\nef = EasyFlake(node_id=0, node_id_bits=4, sequence_bits=6)\nprint(ef.get_id())\n```\n\nThe components of the output ID are the sequence value, node ID, and timestamp, in order from the lower bits.\n\n### Arguments\n\n* `node_id` (int, [NodeIdPool](#nodeidpool)): A unique ID for the current node. This ID should be between 0 and (2 ^ node_id_bits) - 1.\n* `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.\n* `sequence_bits` (int): The maximum number of bits used to represent the sequence number. This argument defaults to 8 / max sequence number is 255.\n* `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).\n* `time_scale` (int): The number of decimal places used to represent the timestamp. This argument defaults to 3 (milliseconds).\n\n### API\n\n#### `NodeIDPool`\n\nThis is a class that manages node IDs in a single-threaded or single-process environment. The default options provided are `GrpcNodeIdPool` and `FileNodeIdPool.` By inheriting from `BaseNodeIdPool`, you can also create your own custom node ID management.\n\n##### `easyflake.FileNodeIdPool`\n\nThis is a file-based node ID management class. Care should be taken in distributed systems, as node IDs are managed by a single file.\n\n###### Arguments\n\n* `endpoint` (str): The path to the file where node IDs are recorded.\n* `bits` (int): The maximum number of bits for node IDs.\n\n##### `easyflake.GrpcNodeIdPool`\n\nThis is a gRPC-based node ID management class.\nYou can start a gRPC server using [`easyflake-cli grpc`](#easyflake-cli-grpc).  \nHowever, it's important to note that the gRPC server can become a single point of failure in your system, so proper measures should be taken to ensure its availability.\n\n###### Arguments\n\n* `endpoint` (str): The address of the gRPC server.\n* `bits` (int): The maximum number of bits for node IDs.\n\n### Command\n\n#### `easyflake-cli grpc`\n\nThis command starts a gRPC server for managing node IDs.\n\n##### `Options`\n\n* `-p`, `--port`: Specifies the port number of the gRPC server.\n* `-d`, `--daemon`: Starts the server in daemon mode (not supported on Windows).\n* `--pid-file`: Specifies the path to the PID file.\n\n## Contributing\n\nSee the [contributing guide](https://github.com/tsuperis/easyflake/blob/main/CONTRIBUTING.md).\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](https://github.com/tsuperis/easyflake/blob/main/LICENSE) file for details.\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "EasyFlake is a Python package for generating 64-bit IDs similar to Snowflake or Sonyflake.",
    "version": "0.3.1",
    "split_keywords": [
        "snowflake",
        "sonyflake",
        "easyflake"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9aab49057d385c61d40f598d55eb207a3a5d367cfcfad68ec92432cb446b3dfc",
                "md5": "4fbd021f4c022b360828005d79eaedcb",
                "sha256": "5cfb7dc56d235a9263640c103cf59a3effbdd203feb088d57c2960f9a47897e8"
            },
            "downloads": -1,
            "filename": "easyflake-0.3.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4fbd021f4c022b360828005d79eaedcb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8,<4.0",
            "size": 17850,
            "upload_time": "2023-03-10T12:07:28",
            "upload_time_iso_8601": "2023-03-10T12:07:28.436869Z",
            "url": "https://files.pythonhosted.org/packages/9a/ab/49057d385c61d40f598d55eb207a3a5d367cfcfad68ec92432cb446b3dfc/easyflake-0.3.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "475d8dfb9cd065efe310e2f67237e367bc485400212d8574e0d19029307c223a",
                "md5": "54c580ff29b1a3c93638d9e0555c8e32",
                "sha256": "8e3d65e3d538832baa6f30a60c6d6848ed55483c736ae1c1800866522abe9105"
            },
            "downloads": -1,
            "filename": "easyflake-0.3.1.tar.gz",
            "has_sig": false,
            "md5_digest": "54c580ff29b1a3c93638d9e0555c8e32",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8,<4.0",
            "size": 14550,
            "upload_time": "2023-03-10T12:07:30",
            "upload_time_iso_8601": "2023-03-10T12:07:30.271537Z",
            "url": "https://files.pythonhosted.org/packages/47/5d/8dfb9cd065efe310e2f67237e367bc485400212d8574e0d19029307c223a/easyflake-0.3.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-10 12:07:30",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "tsuperis",
    "github_project": "easyflake",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "tox": true,
    "lcname": "easyflake"
}
        
Elapsed time: 0.04170s