extrautilities


Nameextrautilities JSON
Version 2.0 PyPI version JSON
download
home_pagehttps://github.com/RandomTimeLP/ExtraUtils
SummaryThis package provides a few extra utilities for Python, like a "RateLimiter" class.
upload_time2024-06-01 15:39:31
maintainerNone
docs_urlNone
authorRandomTimeTV
requires_pythonNone
licenseUnlicensed
keywords ratelimit timebasedtoken getfilecontent callbackvoid validate_dict
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ExtraUtils
will provide a bunch of small functionalities to speedup development.

(In active development, so if you have any suggestions, to make other developers life easier, feel free to submit them.)

# Latest addition

### TimeBasedToken()
Generates a time-based token using two keys: a primary and a secondary. Ideal for encrypting traffic between devices or services without sharing the actual tokens.

**How it works:**
- Utilizes a unified timestamp, rounded to the nearest tenth of a second.
- Uses the primary token as is.
- Applies a transformation to the secondary token for added security.

**Example:**
```py
primary = "1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p"
secondary = "7q8r9s0t1u2v3w4x5y6z7a8b9c0d1e2f"
def main():
    final_token = TimeBasedToken(primary, secondary)

    print(final_token.regenerate())
    enc = final_token.encrypt("Hello World, i am going to be encrypted and decrypted again. : )")
    print(enc)
    dec = final_token.decrypt(enc)
    print(dec)

if __name__ == "__main__":
    main()
```

### RateLimiter()
Limits the rate of operations to prevent overloading. Configurable thresholds, decay rates, and behaviors on limit reaching.

**Example**
```py
# A very simplified example
from ExtraUtils import RateLimiter
rate_limit = RateLimiter(10,15,5,1,True)
# threshold (10) -> increments before rate_limit.hit is set to True
# upperCap (15) -> the highest value the trigger counter will go
# decay_rate (5) -> the amount in triggers to be decremented each decay cycle
# decay_time (1) -> the time in seconds between each decay cycle
# extreme_case (True) -> if an exeption should be raised (if True) or just rate_limit.hit set to True (if False)

def rate_limit_test(i:int):
    rate_limit.increment()
    print(i,rate_limit.hit)

for i in range(20):
    rate_limit_test(i)

# Output:	
#0 False
#(1 to 8) False
#9 False
#Traceback (most recent call last):
#  File "E:\Developement\RTS-Modules\ExtraUtils\showcase.py", line 14, in <module>
#    rate_limit_test(i)
#  File "E:\Developement\RTS-Modules\ExtraUtils\showcase.py", line 5, in rate_limit_test
#    rate_limiter.increment()
#  File "E:\Developement\RTS-Modules\ExtraUtils\ExtraUtils\RateLimit.py", line 30, in increment
#    raise RateLimited()
#ExtraUtils.RateLimit.RateLimited: Rate limit reached
```
Aditional methods are:
```py
RateLimiter().pause_decay()
RateLimiter().resume_decay()
```



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/RandomTimeLP/ExtraUtils",
    "name": "extrautilities",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "RateLimit, timeBasedToken, getFileContent, callbackVoid, validate_dict",
    "author": "RandomTimeTV",
    "author_email": "dergepanzerte1@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/c9/ba/12b3478bf1ce9a5e95e6a09dedbdac912f19a5b9b5477f3c261d1da05e1e/extrautilities-2.0.tar.gz",
    "platform": null,
    "description": "# ExtraUtils\r\nwill provide a bunch of small functionalities to speedup development.\r\n\r\n(In active development, so if you have any suggestions, to make other developers life easier, feel free to submit them.)\r\n\r\n# Latest addition\r\n\r\n### TimeBasedToken()\r\nGenerates a time-based token using two keys: a primary and a secondary. Ideal for encrypting traffic between devices or services without sharing the actual tokens.\r\n\r\n**How it works:**\r\n- Utilizes a unified timestamp, rounded to the nearest tenth of a second.\r\n- Uses the primary token as is.\r\n- Applies a transformation to the secondary token for added security.\r\n\r\n**Example:**\r\n```py\r\nprimary = \"1a2b3c4d5e6f7g8h9i0j1k2l3m4n5o6p\"\r\nsecondary = \"7q8r9s0t1u2v3w4x5y6z7a8b9c0d1e2f\"\r\ndef main():\r\n    final_token = TimeBasedToken(primary, secondary)\r\n\r\n    print(final_token.regenerate())\r\n    enc = final_token.encrypt(\"Hello World, i am going to be encrypted and decrypted again. : )\")\r\n    print(enc)\r\n    dec = final_token.decrypt(enc)\r\n    print(dec)\r\n\r\nif __name__ == \"__main__\":\r\n    main()\r\n```\r\n\r\n### RateLimiter()\r\nLimits the rate of operations to prevent overloading. Configurable thresholds, decay rates, and behaviors on limit reaching.\r\n\r\n**Example**\r\n```py\r\n# A very simplified example\r\nfrom ExtraUtils import RateLimiter\r\nrate_limit = RateLimiter(10,15,5,1,True)\r\n# threshold (10) -> increments before rate_limit.hit is set to True\r\n# upperCap (15) -> the highest value the trigger counter will go\r\n# decay_rate (5) -> the amount in triggers to be decremented each decay cycle\r\n# decay_time (1) -> the time in seconds between each decay cycle\r\n# extreme_case (True) -> if an exeption should be raised (if True) or just rate_limit.hit set to True (if False)\r\n\r\ndef rate_limit_test(i:int):\r\n    rate_limit.increment()\r\n    print(i,rate_limit.hit)\r\n\r\nfor i in range(20):\r\n    rate_limit_test(i)\r\n\r\n# Output:\t\r\n#0 False\r\n#(1 to 8) False\r\n#9 False\r\n#Traceback (most recent call last):\r\n#  File \"E:\\Developement\\RTS-Modules\\ExtraUtils\\showcase.py\", line 14, in <module>\r\n#    rate_limit_test(i)\r\n#  File \"E:\\Developement\\RTS-Modules\\ExtraUtils\\showcase.py\", line 5, in rate_limit_test\r\n#    rate_limiter.increment()\r\n#  File \"E:\\Developement\\RTS-Modules\\ExtraUtils\\ExtraUtils\\RateLimit.py\", line 30, in increment\r\n#    raise RateLimited()\r\n#ExtraUtils.RateLimit.RateLimited: Rate limit reached\r\n```\r\nAditional methods are:\r\n```py\r\nRateLimiter().pause_decay()\r\nRateLimiter().resume_decay()\r\n```\r\n\r\n\r\n",
    "bugtrack_url": null,
    "license": "Unlicensed",
    "summary": "This package provides a few extra utilities for Python, like a \"RateLimiter\" class.",
    "version": "2.0",
    "project_urls": {
        "Homepage": "https://github.com/RandomTimeLP/ExtraUtils"
    },
    "split_keywords": [
        "ratelimit",
        " timebasedtoken",
        " getfilecontent",
        " callbackvoid",
        " validate_dict"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3c5b6b7d6d7f8f7ff768bba7966d532e682c0f4b1c6a7a3b881ffd7d5d1e2dd9",
                "md5": "a0c6510279ed0bfffc3af583ce89f902",
                "sha256": "b80d3c1a6e19aace21eab36790787e2f07d519e7a372a432ed10ef8a9b27a62c"
            },
            "downloads": -1,
            "filename": "extrautilities-2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a0c6510279ed0bfffc3af583ce89f902",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 8381,
            "upload_time": "2024-06-01T15:39:29",
            "upload_time_iso_8601": "2024-06-01T15:39:29.644093Z",
            "url": "https://files.pythonhosted.org/packages/3c/5b/6b7d6d7f8f7ff768bba7966d532e682c0f4b1c6a7a3b881ffd7d5d1e2dd9/extrautilities-2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c9ba12b3478bf1ce9a5e95e6a09dedbdac912f19a5b9b5477f3c261d1da05e1e",
                "md5": "e24a253bdd9524ffd50270fc252941a2",
                "sha256": "3d550b262327303128ee19ae56e9c0e50a2b77c096335cb15b3a2745e7c28966"
            },
            "downloads": -1,
            "filename": "extrautilities-2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "e24a253bdd9524ffd50270fc252941a2",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 6919,
            "upload_time": "2024-06-01T15:39:31",
            "upload_time_iso_8601": "2024-06-01T15:39:31.402168Z",
            "url": "https://files.pythonhosted.org/packages/c9/ba/12b3478bf1ce9a5e95e6a09dedbdac912f19a5b9b5477f3c261d1da05e1e/extrautilities-2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-01 15:39:31",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "RandomTimeLP",
    "github_project": "ExtraUtils",
    "github_not_found": true,
    "lcname": "extrautilities"
}
        
Elapsed time: 0.25020s