aiofreqlimit
Advanced tools
+37
| # Frequency Limit Context Manager for asyncio | ||
| [](https://pypi.org/project/aiofreqlimit) | ||
| [](https://github.com/gleb-chipiga/aiofreqlimit/blob/master/LICENSE) | ||
| [](https://pypistats.org/packages/aiofreqlimit) | ||
| ## Installation | ||
| aiofreqlimit requires Python 3.11 or greater and is available on PyPI. Use pip to install it: | ||
| ```bash | ||
| pip install aiofreqlimit | ||
| ``` | ||
| ## Using aiofreqlimit | ||
| Pass a value of any hashable type to `acquire`, or omit the argument to use the default key: | ||
| ```python | ||
| import asyncio | ||
| from aiofreqlimit import FreqLimit | ||
| limit = FreqLimit(1 / 10) | ||
| async def job(): | ||
| async with limit.acquire("some_key"): | ||
| await some_call() | ||
| async def main(): | ||
| await asyncio.gather(job() for _ in range(100)) | ||
| asyncio.run(main()) | ||
| ``` |
| from __future__ import annotations | ||
| from importlib import metadata | ||
| from pathlib import Path | ||
| from typing import cast | ||
| try: | ||
| __version__: str = metadata.version("aiofreqlimit") | ||
| except metadata.PackageNotFoundError: # pragma: no cover - local fallback | ||
| import tomllib | ||
| root = Path(__file__).resolve().parents[1] | ||
| pyproject_path = root / "pyproject.toml" | ||
| with pyproject_path.open("rb") as pyproject_file: | ||
| pyproject: dict[str, object] = tomllib.load(pyproject_file) | ||
| project = pyproject.get("project") | ||
| if not isinstance(project, dict): | ||
| msg = "'project' section missing in pyproject.toml" | ||
| raise RuntimeError(msg) from None | ||
| project_table = cast(dict[str, object], project) | ||
| version_value = project_table.get("version") | ||
| if not isinstance(version_value, str): | ||
| msg = "'project.version' must be a string in pyproject.toml" | ||
| raise RuntimeError(msg) from None | ||
| __version__ = version_value | ||
| __all__ = ("__version__",) |
+23
-33
| Metadata-Version: 2.3 | ||
| Name: aiofreqlimit | ||
| Version: 0.1.1 | ||
| Version: 0.1.3 | ||
| Summary: Frequency limit for asyncio | ||
@@ -43,50 +43,40 @@ Author: Gleb Chipiga | ||
| Project-URL: Homepage, https://github.com/gleb-chipiga/aiofreqlimit | ||
| Description-Content-Type: text/x-rst | ||
| Description-Content-Type: text/markdown | ||
| =========================================== | ||
| Frequency limit context manager for asyncio | ||
| =========================================== | ||
| # Frequency Limit Context Manager for asyncio | ||
| .. image:: https://badge.fury.io/py/aiofreqlimit.svg | ||
| :target: https://pypi.org/project/aiofreqlimit | ||
| :alt: Latest PyPI package version | ||
| [](https://pypi.org/project/aiofreqlimit) | ||
| [](https://github.com/gleb-chipiga/aiofreqlimit/blob/master/LICENSE) | ||
| [](https://pypistats.org/packages/aiofreqlimit) | ||
| .. image:: https://img.shields.io/badge/license-MIT-blue.svg | ||
| :target: https://github.com/gleb-chipiga/aiofreqlimit/blob/master/LICENSE | ||
| :alt: License | ||
| ## Installation | ||
| .. image:: https://img.shields.io/pypi/dm/aiofreqlimit | ||
| :target: https://pypistats.org/packages/aiofreqlimit | ||
| :alt: Downloads count | ||
| Installation | ||
| ============ | ||
| aiofreqlimit requires Python 3.11 or greater and is available on PyPI. Use pip to install it: | ||
| .. code-block:: bash | ||
| ```bash | ||
| pip install aiofreqlimit | ||
| ``` | ||
| pip install aiofreqlimit | ||
| ## Using aiofreqlimit | ||
| Using aiofreqlimit | ||
| ================== | ||
| Pass a value of any hashable type to `acquire` or do not specify any parameter: | ||
| Pass a value of any hashable type to `acquire`, or omit the argument to use the default key: | ||
| .. code-block:: python | ||
| ```python | ||
| import asyncio | ||
| import asyncio | ||
| from aiofreqlimit import FreqLimit | ||
| from aiofreqlimit import FreqLimit | ||
| limit = FreqLimit(1 / 10) | ||
| limit = FreqLimit(1 / 10) | ||
| async def job(): | ||
| async with limit.acquire("some_key"): | ||
| await some_call() | ||
| async def job(): | ||
| async with limit.acquire('some_key'): | ||
| await some_call() | ||
| async def main(): | ||
| await asyncio.gather(job() for _ in range(100)) | ||
| async def main(): | ||
| await asyncio.gather(job() for _ in range(100)) | ||
| asyncio.run(main()) | ||
| asyncio.run(main()) | ||
| ``` |
+2
-2
@@ -7,5 +7,5 @@ [build-system] | ||
| name = "aiofreqlimit" | ||
| version = "0.1.1" | ||
| version = "0.1.3" | ||
| description = "Frequency limit for asyncio" | ||
| readme = "README.rst" | ||
| readme = "README.md" | ||
| license = { file = "LICENSE" } | ||
@@ -12,0 +12,0 @@ authors = [{ name = "Gleb Chipiga" }] |
@@ -7,4 +7,5 @@ import asyncio | ||
| from ._version import __version__ | ||
| __all__ = ("FreqLimit", "__version__") | ||
| __version__ = "0.0.16" | ||
@@ -11,0 +12,0 @@ |
-47
| =========================================== | ||
| Frequency limit context manager for asyncio | ||
| =========================================== | ||
| .. image:: https://badge.fury.io/py/aiofreqlimit.svg | ||
| :target: https://pypi.org/project/aiofreqlimit | ||
| :alt: Latest PyPI package version | ||
| .. image:: https://img.shields.io/badge/license-MIT-blue.svg | ||
| :target: https://github.com/gleb-chipiga/aiofreqlimit/blob/master/LICENSE | ||
| :alt: License | ||
| .. image:: https://img.shields.io/pypi/dm/aiofreqlimit | ||
| :target: https://pypistats.org/packages/aiofreqlimit | ||
| :alt: Downloads count | ||
| Installation | ||
| ============ | ||
| aiofreqlimit requires Python 3.11 or greater and is available on PyPI. Use pip to install it: | ||
| .. code-block:: bash | ||
| pip install aiofreqlimit | ||
| Using aiofreqlimit | ||
| ================== | ||
| Pass a value of any hashable type to `acquire` or do not specify any parameter: | ||
| .. code-block:: python | ||
| import asyncio | ||
| from aiofreqlimit import FreqLimit | ||
| limit = FreqLimit(1 / 10) | ||
| async def job(): | ||
| async with limit.acquire('some_key'): | ||
| await some_call() | ||
| async def main(): | ||
| await asyncio.gather(job() for _ in range(100)) | ||
| asyncio.run(main()) |
Alert delta unavailable
Currently unable to show alert delta for PyPI packages.
12429
4.47%7
16.67%108
27.06%