snowflake-id


Namesnowflake-id JSON
Version 1.0.2 PyPI version JSON
download
home_pagehttps://github.com/vd2org/snowflake
SummaryThe Snowflake generator done right
upload_time2024-04-17 13:36:05
maintainerNone
docs_urlNone
authorNone
requires_python<4.0,>=3.8
licenseMIT License Copyright (c) 2021-2024 Vd Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords snowflake snowflake-id id ids generator
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Snowflake

The Snowflake generator done right.

See [here](https://en.wikipedia.org/wiki/Snowflake_ID) for additional information.

### Requirements

Python 3.8 and above. No additional dependencies.

### Installation

`pip install snowflake-id`

## Usage

### Using generator

```python
from snowflake import SnowflakeGenerator

gen = SnowflakeGenerator(42)

for i in range(100):
    val = next(gen)
    print(val)
```

#### Output:

```text
6820698575169822721
6820698575169822722
6820698575169822723
6820698575174017024
6820698575174017025
...
```

### Parse snowflake id

```python
from snowflake import Snowflake

sf = Snowflake.parse(856165981072306191, 1288834974657)

print(f"{sf.timestamp = }")
print(f"{sf.instance = }")
print(f"{sf.epoch = }")
print(f"{sf.seq = }")
print(f"{sf.seconds = }")
print(f"{sf.milliseconds = }")
print(f"{sf.datetime = }")
print(f"{int(sf) = }")
```

#### Output:

```text
sf.timestamp = 204125876682
sf.instance = 363
sf.epoch = 1288834974657
sf.seq = 15
sf.seconds = 1492960851.339
sf.milliseconds = 1492960851339
sf.datetime = datetime.datetime(2017, 4, 23, 15, 20, 51, 339000)
int(sf) = 856165981072306191
```

### Load generator state

```python
from snowflake import SnowflakeGenerator, Snowflake

sf = Snowflake.parse(856165981072306191, 1288834974657)
gen = SnowflakeGenerator.from_snowflake(sf)

for i in range(100):
    val = next(gen)
    print(val)
```

#### Output:

```text
1414934653136449536
1414934653136449537
1414934653136449538
1414934653136449539
1414934653136449540
...
```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/vd2org/snowflake",
    "name": "snowflake-id",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.8",
    "maintainer_email": null,
    "keywords": "snowflake, snowflake-id, id, ids, generator",
    "author": null,
    "author_email": "vd <snowflake@vd2.org>",
    "download_url": "https://files.pythonhosted.org/packages/7a/d0/91bd3d2e54ea849e8c4e73681ef75c1c93f37a8c9f0627b1553522267e08/snowflake_id-1.0.2.tar.gz",
    "platform": null,
    "description": "# Snowflake\n\nThe Snowflake generator done right.\n\nSee [here](https://en.wikipedia.org/wiki/Snowflake_ID) for additional information.\n\n### Requirements\n\nPython 3.8 and above. No additional dependencies.\n\n### Installation\n\n`pip install snowflake-id`\n\n## Usage\n\n### Using generator\n\n```python\nfrom snowflake import SnowflakeGenerator\n\ngen = SnowflakeGenerator(42)\n\nfor i in range(100):\n    val = next(gen)\n    print(val)\n```\n\n#### Output:\n\n```text\n6820698575169822721\n6820698575169822722\n6820698575169822723\n6820698575174017024\n6820698575174017025\n...\n```\n\n### Parse snowflake id\n\n```python\nfrom snowflake import Snowflake\n\nsf = Snowflake.parse(856165981072306191, 1288834974657)\n\nprint(f\"{sf.timestamp = }\")\nprint(f\"{sf.instance = }\")\nprint(f\"{sf.epoch = }\")\nprint(f\"{sf.seq = }\")\nprint(f\"{sf.seconds = }\")\nprint(f\"{sf.milliseconds = }\")\nprint(f\"{sf.datetime = }\")\nprint(f\"{int(sf) = }\")\n```\n\n#### Output:\n\n```text\nsf.timestamp = 204125876682\nsf.instance = 363\nsf.epoch = 1288834974657\nsf.seq = 15\nsf.seconds = 1492960851.339\nsf.milliseconds = 1492960851339\nsf.datetime = datetime.datetime(2017, 4, 23, 15, 20, 51, 339000)\nint(sf) = 856165981072306191\n```\n\n### Load generator state\n\n```python\nfrom snowflake import SnowflakeGenerator, Snowflake\n\nsf = Snowflake.parse(856165981072306191, 1288834974657)\ngen = SnowflakeGenerator.from_snowflake(sf)\n\nfor i in range(100):\n    val = next(gen)\n    print(val)\n```\n\n#### Output:\n\n```text\n1414934653136449536\n1414934653136449537\n1414934653136449538\n1414934653136449539\n1414934653136449540\n...\n```\n",
    "bugtrack_url": null,
    "license": "MIT License\n        \n        Copyright (c) 2021-2024 Vd\n        \n        Permission is hereby granted, free of charge, to any person obtaining a copy\n        of this software and associated documentation files (the \"Software\"), to deal\n        in the Software without restriction, including without limitation the rights\n        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n        copies of the Software, and to permit persons to whom the Software is\n        furnished to do so, subject to the following conditions:\n        \n        The above copyright notice and this permission notice shall be included in all\n        copies or substantial portions of the Software.\n        \n        THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n        SOFTWARE.",
    "summary": "The Snowflake generator done right",
    "version": "1.0.2",
    "project_urls": {
        "Homepage": "https://github.com/vd2org/snowflake",
        "Issues": "https://github.com/vd2org/snowflake/issues",
        "Repository": "https://github.com/vd2org/snowflake.git"
    },
    "split_keywords": [
        "snowflake",
        " snowflake-id",
        " id",
        " ids",
        " generator"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "41a4ee0bdba1d1e98db21166381559d0061d752bbf66af2dd1cbbe4c2afdc4fa",
                "md5": "eb733b1934deaa44c1b8210a073cc116",
                "sha256": "c3142752ed334b9d4632739a704461d13e97aa6fa71b65d5329829b4b5cc058c"
            },
            "downloads": -1,
            "filename": "snowflake_id-1.0.2-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "eb733b1934deaa44c1b8210a073cc116",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.8",
            "size": 4795,
            "upload_time": "2024-04-17T13:36:03",
            "upload_time_iso_8601": "2024-04-17T13:36:03.898953Z",
            "url": "https://files.pythonhosted.org/packages/41/a4/ee0bdba1d1e98db21166381559d0061d752bbf66af2dd1cbbe4c2afdc4fa/snowflake_id-1.0.2-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "7ad091bd3d2e54ea849e8c4e73681ef75c1c93f37a8c9f0627b1553522267e08",
                "md5": "35abadd937601d4d78e8b053d95814f0",
                "sha256": "4a4cd49508599aaa16488311f4b9121e9ac3bac57edff3e9f71b1d79086dbfe8"
            },
            "downloads": -1,
            "filename": "snowflake_id-1.0.2.tar.gz",
            "has_sig": false,
            "md5_digest": "35abadd937601d4d78e8b053d95814f0",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.8",
            "size": 4497,
            "upload_time": "2024-04-17T13:36:05",
            "upload_time_iso_8601": "2024-04-17T13:36:05.552378Z",
            "url": "https://files.pythonhosted.org/packages/7a/d0/91bd3d2e54ea849e8c4e73681ef75c1c93f37a8c9f0627b1553522267e08/snowflake_id-1.0.2.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-04-17 13:36:05",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "vd2org",
    "github_project": "snowflake",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "snowflake-id"
}
        
Elapsed time: 0.23510s