snowflake-util


Namesnowflake-util JSON
Version 1.0.0b7 PyPI version JSON
download
home_pageNone
SummaryA Python library for generating snowflakes.
upload_time2024-11-26 16:03:57
maintainerNone
docs_urlNone
authorTheMultii
requires_pythonNone
licenseNone
keywords python snowflake generator custom library id generator uid
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
# snowflake-util



A Python library for generating Discord, Twitter, Instagram and custom snowflakes.



A snowflake is a unique identifier for a resource that includes, among other things, a timestamp of when such a snowflake was created. Snowflakes are used by Twitter, Discord or Instagram. They were created by Twitter in 2010.



Developed by TheMultii (c) 2022-present



## Installing

```bash

# Linux/macOS

python3 -m pip install -U snowflake-util



# Windows

py -3 -m pip install -U snowflake-util

```



## Examples of How To Use



Creating a custom snowflake



```python

from datetime import datetime

import snowflake



config = snowflake.SnowflakeConfig(

    epoch=snowflake.Epoch.discord, # or Unix timestamp in milliseconds with maximum length of 13 digits.

    leading_bit=False,

    timestamp_length=42,

    param1_length=5,

    param2_length=5,

    sequence_length=12

)



SnowClass = snowflake.Snowflake(config)



custom_snowflake = SnowClass.generate_snowflake(param1=11, param2=3, sequence=753)

custom_snowflake_TS = SnowClass.generate_snowflake(param1=14, param2=9, sequence=357, date=datetime(2021, 8, 8, 8, 8, 0, 0))



print(custom_snowflake, SnowClass.parse_snowflake(custom_snowflake))

print(custom_snowflake_TS, SnowClass.parse_snowflake(custom_snowflake_TS))

```



Creating a Discord snowflake

```python

SnowClass = snowflake.Snowflake()



discord_snowflake = SnowClass.generate_discord_snowflake(worker=5, process=5, sequence=222, date=datetime(2022, 1, 1, 16, 15, 0, 0))



print(discord_snowflake, SnowClass.parse_discord_snowflake(discord_snowflake))

```



Creating a Twitter snowflake

```python

SnowClass = snowflake.Snowflake()



twitter_snowflake = SnowClass.generate_twitter_snowflake(machine=333, sequence=666, date=datetime(2022, 1, 1, 16, 15, 0, 0))



print(twitter_snowflake, SnowClass.parse_twitter_snowflake(twitter_snowflake))

```



Creating an Instagram snowflake

```python

SnowClass = snowflake.Snowflake()



instagram_snowflake = SnowClass.generate_instagram_snowflake(shard=1605, sequence=420, date=datetime(2020, 6, 11, 8 ,13))



print(instagram_snowflake, SnowClass.parse_instagram_snowflake(instagram_snowflake))

```



## IMPORTANT INFO:

- Generating any snowflakes does not require sending the date as an argument - the snowflake will be generated based on the current time.

- `snowflake.SnowflakeConfig` is not required if you want to use any of the ready-made templates for generating/reading snowflakes (Twitter, Discord, Instagram)

- You can edit and read the current configuration settings using the `Snowflake.set_config()` and `Snowflake.get_config()` methods.

- All methods are documented in the code.

- The `leading_bit` is used by Twitter to generate snowflakes.

- For custom configuration, sum of `leading_bit, timestamp_length, param1_length, param2_length, sequence_length` must be exactly 64.

- Snowflakes can only be generated for dates that are after the set epoch.

- There must be a 64-bit representation for each snowflake.





## References

- https://en.wikipedia.org/wiki/Snowflake_ID

- https://blog.twitter.com/engineering/en_us/a/2010/announcing-snowflake



## License

MIT

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "snowflake-util",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "python, snowflake, generator, custom, library, id generator, uid",
    "author": "TheMultii",
    "author_email": null,
    "download_url": "https://files.pythonhosted.org/packages/21/77/67f6825cd881429eb758daa5bfaf1e583c742968e5d2fc922f3640bd681f/snowflake_util-1.0.0b7.tar.gz",
    "platform": null,
    "description": "\r\n# snowflake-util\r\r\n\r\r\nA Python library for generating Discord, Twitter, Instagram and custom snowflakes.\r\r\n\r\r\nA snowflake is a unique identifier for a resource that includes, among other things, a timestamp of when such a snowflake was created. Snowflakes are used by Twitter, Discord or Instagram. They were created by Twitter in 2010.\r\r\n\r\r\nDeveloped by TheMultii (c) 2022-present\r\r\n\r\r\n## Installing\r\r\n```bash\r\r\n# Linux/macOS\r\r\npython3 -m pip install -U snowflake-util\r\r\n\r\r\n# Windows\r\r\npy -3 -m pip install -U snowflake-util\r\r\n```\r\r\n\r\r\n## Examples of How To Use\r\r\n\r\r\nCreating a custom snowflake\r\r\n\r\r\n```python\r\r\nfrom datetime import datetime\r\r\nimport snowflake\r\r\n\r\r\nconfig = snowflake.SnowflakeConfig(\r\r\n    epoch=snowflake.Epoch.discord, # or Unix timestamp in milliseconds with maximum length of 13 digits.\r\r\n    leading_bit=False,\r\r\n    timestamp_length=42,\r\r\n    param1_length=5,\r\r\n    param2_length=5,\r\r\n    sequence_length=12\r\r\n)\r\r\n\r\r\nSnowClass = snowflake.Snowflake(config)\r\r\n\r\r\ncustom_snowflake = SnowClass.generate_snowflake(param1=11, param2=3, sequence=753)\r\r\ncustom_snowflake_TS = SnowClass.generate_snowflake(param1=14, param2=9, sequence=357, date=datetime(2021, 8, 8, 8, 8, 0, 0))\r\r\n\r\r\nprint(custom_snowflake, SnowClass.parse_snowflake(custom_snowflake))\r\r\nprint(custom_snowflake_TS, SnowClass.parse_snowflake(custom_snowflake_TS))\r\r\n```\r\r\n\r\r\nCreating a Discord snowflake\r\r\n```python\r\r\nSnowClass = snowflake.Snowflake()\r\r\n\r\r\ndiscord_snowflake = SnowClass.generate_discord_snowflake(worker=5, process=5, sequence=222, date=datetime(2022, 1, 1, 16, 15, 0, 0))\r\r\n\r\r\nprint(discord_snowflake, SnowClass.parse_discord_snowflake(discord_snowflake))\r\r\n```\r\r\n\r\r\nCreating a Twitter snowflake\r\r\n```python\r\r\nSnowClass = snowflake.Snowflake()\r\r\n\r\r\ntwitter_snowflake = SnowClass.generate_twitter_snowflake(machine=333, sequence=666, date=datetime(2022, 1, 1, 16, 15, 0, 0))\r\r\n\r\r\nprint(twitter_snowflake, SnowClass.parse_twitter_snowflake(twitter_snowflake))\r\r\n```\r\r\n\r\r\nCreating an Instagram snowflake\r\r\n```python\r\r\nSnowClass = snowflake.Snowflake()\r\r\n\r\r\ninstagram_snowflake = SnowClass.generate_instagram_snowflake(shard=1605, sequence=420, date=datetime(2020, 6, 11, 8 ,13))\r\r\n\r\r\nprint(instagram_snowflake, SnowClass.parse_instagram_snowflake(instagram_snowflake))\r\r\n```\r\r\n\r\r\n## IMPORTANT INFO:\r\r\n- Generating any snowflakes does not require sending the date as an argument - the snowflake will be generated based on the current time.\r\r\n- `snowflake.SnowflakeConfig` is not required if you want to use any of the ready-made templates for generating/reading snowflakes (Twitter, Discord, Instagram)\r\r\n- You can edit and read the current configuration settings using the `Snowflake.set_config()` and `Snowflake.get_config()` methods.\r\r\n- All methods are documented in the code.\r\r\n- The `leading_bit` is used by Twitter to generate snowflakes.\r\r\n- For custom configuration, sum of `leading_bit, timestamp_length, param1_length, param2_length, sequence_length` must be exactly 64.\r\r\n- Snowflakes can only be generated for dates that are after the set epoch.\r\r\n- There must be a 64-bit representation for each snowflake.\r\r\n\r\r\n\r\r\n## References\r\r\n- https://en.wikipedia.org/wiki/Snowflake_ID\r\r\n- https://blog.twitter.com/engineering/en_us/a/2010/announcing-snowflake\r\r\n\r\r\n## License\r\r\nMIT\r\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "A Python library for generating snowflakes.",
    "version": "1.0.0b7",
    "project_urls": {
        "Repository": "https://github.com/TheMultii/snowflake-util"
    },
    "split_keywords": [
        "python",
        " snowflake",
        " generator",
        " custom",
        " library",
        " id generator",
        " uid"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "97802b882a1ffdaab00ee3bd4afa71878e38f49cd3a5f72c53a30342f1b918f8",
                "md5": "3f84e3ef0b967359aae5154a393d417c",
                "sha256": "d9bb2af433f42c57fefeeaf399ebf8e4ee691fccb8dfb82b86104b44fda0fb4f"
            },
            "downloads": -1,
            "filename": "snowflake_util-1.0.0b7-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "3f84e3ef0b967359aae5154a393d417c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 10137,
            "upload_time": "2024-11-26T16:03:56",
            "upload_time_iso_8601": "2024-11-26T16:03:56.593241Z",
            "url": "https://files.pythonhosted.org/packages/97/80/2b882a1ffdaab00ee3bd4afa71878e38f49cd3a5f72c53a30342f1b918f8/snowflake_util-1.0.0b7-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "217767f6825cd881429eb758daa5bfaf1e583c742968e5d2fc922f3640bd681f",
                "md5": "a559fa84e766ffb21c42238fee0bb682",
                "sha256": "9af24b34f834b2631ef65c738d021decc24ab9e49a8347647d17e57f7b53165a"
            },
            "downloads": -1,
            "filename": "snowflake_util-1.0.0b7.tar.gz",
            "has_sig": false,
            "md5_digest": "a559fa84e766ffb21c42238fee0bb682",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 8104,
            "upload_time": "2024-11-26T16:03:57",
            "upload_time_iso_8601": "2024-11-26T16:03:57.531559Z",
            "url": "https://files.pythonhosted.org/packages/21/77/67f6825cd881429eb758daa5bfaf1e583c742968e5d2fc922f3640bd681f/snowflake_util-1.0.0b7.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-26 16:03:57",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "TheMultii",
    "github_project": "snowflake-util",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "snowflake-util"
}
        
Elapsed time: 1.03258s