{"id":23204720,"url":"https://github.com/mghorbani2357/function-limiter","last_synced_at":"2025-08-25T00:32:00.326Z","repository":{"id":47587293,"uuid":"329346089","full_name":"mghorbani2357/Function-Limiter","owner":"mghorbani2357","description":"Function Limiter designed to limit the call rate of callable function in python. It can be used in Flask, Django, WebSocket, etc.","archived":false,"fork":false,"pushed_at":"2024-05-13T05:08:47.000Z","size":136,"stargazers_count":5,"open_issues_count":2,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-12-17T18:48:54.663Z","etag":null,"topics":["limiter","python","python3"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mghorbani2357.png","metadata":{"files":{"readme":"README.rst","changelog":"HISTORY.rst","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["mghorbani2357"]}},"created_at":"2021-01-13T15:13:49.000Z","updated_at":"2024-05-13T05:08:50.000Z","dependencies_parsed_at":"2022-08-30T21:02:21.973Z","dependency_job_id":null,"html_url":"https://github.com/mghorbani2357/Function-Limiter","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mghorbani2357%2FFunction-Limiter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mghorbani2357%2FFunction-Limiter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mghorbani2357%2FFunction-Limiter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mghorbani2357%2FFunction-Limiter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mghorbani2357","download_url":"https://codeload.github.com/mghorbani2357/Function-Limiter/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230852606,"owners_count":18290081,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["limiter","python","python3"],"created_at":"2024-12-18T16:19:54.051Z","updated_at":"2024-12-22T15:53:54.937Z","avatar_url":"https://github.com/mghorbani2357.png","language":"Python","funding_links":["https://github.com/sponsors/mghorbani2357"],"categories":[],"sub_categories":[],"readme":".. |license| image:: https://img.shields.io/github/license/mghorbani2357/function-limiter\n    :target: https://raw.githubusercontent.com/mghorbani2357/Function-Limiter/master/LICENSE\n    :alt: GitHub Licence\n    \n.. |build| image:: https://travis-ci.com/mghorbani2357/Function-Limiter.svg?branch=master\n    :target: https://travis-ci.com/mghorbani2357/Function-Limiter\n    \n.. |codecov| image:: https://codecov.io/gh/mghorbani2357/Function-Limiter/branch/master/graph/badge.svg?token=V606VBKSGK\n    :target: https://codecov.io/gh/mghorbani2357/Function-Limiter\n\n..  |quality| image:: https://api.codacy.com/project/badge/Grade/4ec8eeac03144927aef804e2388b7988\n    :target: https://app.codacy.com/gh/mghorbani2357/Function-Limiter?utm_source=github.com\u0026utm_medium=referral\u0026utm_content=mghorbani2357/Function-Limiter\u0026utm_campaign=Badge_Grade\n   \n.. |coverage| image:: https://app.codacy.com/project/badge/Coverage/ebc9c5345a4f48bda082b09b815cee57   \n    :target: https://www.codacy.com/gh/mghorbani2357/Function-Limiter/dashboard?utm_source=github.com\u0026utm_medium=referral\u0026utm_content=mghorbani2357/Function-Limiter\u0026utm_campaign=Badge_Coverage\n\n.. |downloadrate| image:: https://img.shields.io/pypi/dm/Function-Limiter\n    :target: https://pypistats.org/packages/function-limiter\n    \n.. |wheel| image:: https://img.shields.io/pypi/wheel/Function-Limiter  \n    :target: https://pypi.python.org/pypi/Function-Limiter\n    :alt: PyPI - Wheel\n    \n.. |pypiversion| image:: https://img.shields.io/pypi/v/Function-Limiter  \n    :target: https://pypi.python.org/pypi/Function-Limiter\n    :alt: PyPI\n    \n.. |format| image:: https://img.shields.io/pypi/format/Function-Limiter\n    :target: https://pypi.python.org/pypi/Function-Limiter\n    :alt: PyPI - Format\n    \n.. |downloads| image:: https://static.pepy.tech/personalized-badge/function-limiter?period=total\u0026units=international_system\u0026left_color=grey\u0026right_color=blue\u0026left_text=Downloads\n    :target: https://pepy.tech/project/function-limiter\n    \n.. |readthedocs| image:: https://readthedocs.org/projects/function-limiter/badge/?version=latest\n    :target: https://function-limiter.readthedocs.io/en/latest/?badge=latest\n    :alt: Documentation Status\n\n\n.. |lastcommit| image:: https://img.shields.io/github/last-commit/mghorbani2357/function-limiter \n    :alt: GitHub last commit\n    \n.. |lastrelease| image:: https://img.shields.io/github/release-date/mghorbani2357/function-limiter   \n    :alt: GitHub Release Date\n\n.. |workflow| image:: https://img.shields.io/github/workflow/status/mghorbani2357/function-limiter/main?logo=github   \n    :alt: GitHub Workflow Status\n\n*****************\nFunction-Limiter\n*****************\n\n.. class:: center\n\n |license| |build| |workflow| |codecov| |quality| |coverage| |downloadrate| |downloads| |pypiversion| |format| |wheel| |lastcommit| |lastrelease|\n\n\nFunction-Limiter provides call rate limitation of callable function.\n\nInstallation\n============\n\n.. code-block:: bash\n\n    pip install Function-Limiter\n\n\nQuick Start\n===========\n\nAdd the rate limiter to your function as decorator. The following example uses the default\nin memory implementation. ``Limiter()`` create instance of limiter.\nBy using ``limiter.limit()`` call rate of callable function become limited.\n``limiter.limit(limitation, key)`` limitation get the limitation can be assigned number per one of these keywords (second, minute, hour, day, month, year).\nLimitation applied on defined key.\n\n\n.. code-block:: python\n\n    from function_limiter.limiter import Limiter\n    from function_limiter.limiter import RateLimitExceeded\n    import time\n\n    limiter = Limiter()\n\n\n    @limiter.limit('3/second', 'key')\n    def function():\n        print('hello world!')\n\n\n\n.. code-block:: python\n\n    from function_limiter.limiter import Limiter\n    from function_limiter.limiter import RateLimitExceeded\n    import time\n    import redis\n\n    limiter = Limiter(\n            storage_uri=redis.Redis()\n        )\n\n\nThere are a few ways of using this decorator depending on your preference and use-case.\n\n\nSingle decorator\n================\n\nThe limit string can be a single limit or a delimiter separated string\n\n.. code-block:: python\n\n    @limiter.limit('3/second;10 per minute', 'key')\n    def function():\n        print('hello world!')\n\n\nCustom keying function\n======================\n\nYou can implement your own function to retrieve the value of rate limit config.\n\n.. code-block:: python\n\n    def limitation():\n        return '5/second'\n\n    def key():\n        return 'custom key'\n\n    @limiter.limit(limitation, key=key)\n    def function():\n        print('hello world!')\n\n\n\nRedis storage\n======================\n\nRedis storage can be involved to lunch multiple instance of application.\n\n.. code-block:: python\n\n    limiter = Limiter(\n        storage_uri=redis.Redis()\n    )\n\n    @limiter.limit('3/minute', 'key')\n    def func():\n        pass\n\n\nExempt key\n======================\n\nExempt key can be used to exempt defined keys. If key and exempt key matched it ignores the limitations\n\n.. code-block:: python\n\n    limiter = Limiter()\n\n    @limiter.limit('3/minute', 'key', exempt='key')\n    def func():\n        pass\n\nDefault values\n===============\n\nYou can define rate limit default value when the Limiter instance was initialized.\nBy defining default rate limit values if there isn't any value for the specific key it applies the default value.\n\n.. code-block:: python\n\n    limiter = Limiter(\n        default_limitations='3/minute',\n        default_key='key',\n        default_exempt='key'\n    )\n\n    @limiter.limit()\n    def func():\n        pass\n\n\nLimitation reset\n=================\n\nLimitation can be reset for specific key.\n\n.. code-block:: python\n\n    limiter = Limiter()\n\n    @limiter.limit('3 per second', 'key')\n    def func():\n        pass\n\n    for _ in range(3):\n       func()\n\n    limiter.reset('key')\n\n    for _ in range(3):\n       func()\n\n\nAsynchronous function limit\n===========================\n\nLimitation can be reset for specific key.\n\n.. code-block:: python\n\n    limiter = Limiter()\n\n    @limiter.limit('3 per second', 'key')\n    async def func():\n        pass\n\n    for _ in range(3):\n       func()\n\n    limiter.reset('key')\n\n    for _ in range(3):\n       func()\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmghorbani2357%2Ffunction-limiter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmghorbani2357%2Ffunction-limiter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmghorbani2357%2Ffunction-limiter/lists"}