redguard


Nameredguard JSON
Version 0.1.0 PyPI version JSON
download
home_pageNone
SummaryDistributed synchronization primitives buit on top of Redis
upload_time2025-02-16 21:39:23
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseNone
keywords distributed limiter lock mutex rate redis semaphore synchronization
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ![Tests](https://github.com/asynq-io/redguard/workflows/Tests/badge.svg)
![Build](https://github.com/asynq-io/redguard/workflows/Publish/badge.svg)
![License](https://img.shields.io/github/license/asynq-io/redguard)
![Python](https://img.shields.io/pypi/pyversions/redguard)
![Format](https://img.shields.io/pypi/format/redguard)
![PyPi](https://img.shields.io/pypi/v/redguard)
![Mypy](https://img.shields.io/badge/mypy-checked-blue)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v1.json)](https://github.com/charliermarsh/ruff)
[![security: bandit](https://img.shields.io/badge/security-bandit-yellow.svg)](https://github.com/PyCQA/bandit)

# redguard

Distributed synchronization primitives buit on top of Redis

## Installation

```shell
pip install redguard
```

## Available primitives

- `Lock` - distributed mutex
- `Semaphore` - distributed semaphore
- `RateLimiter` - distributed rate limiter

## Helpers

- `RedGuard` - factory for creating primitives
- `SharedResourcePool` - factory for creating shared resources

## Usage

The api is similar to built-in `asyncio` module primitives.

```python
from redguard import RedGuard
from redguard.lock import Lock

guard = RedGuard.from_url("redis://localhost:6379")

async def lock_example():
    lock = guard.new(Lock, "my-lock")

    async with lock:
        print("Locked")

async def semaphore_example():
    semaphore = guard.new(Semaphore, "my-semaphore", capacity=2)

    async with semaphore:
        print("Acquired")

async def rate_limiter_example():
    rate_limiter = guard.new(RateLimiter, "my-rate-limiter", limit=2, window=1)

    async with rate_limiter:
        print("Rate limited")

```

### Lower level api

Each primitve can be used as async context manager, but also provides `acquire` and `release` methods.

```python

semaphore = guard.new(Semaphore, "my-semaphore", capacity=2)

acquired = await semaphore.acquire(blocking=True, timeout=None) # returns True if acquired (useful for blocking=False)

if acquired:
    await semaphore.release()

```

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "redguard",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "distributed, limiter, lock, mutex, rate, redis, semaphore, synchronization",
    "author": null,
    "author_email": "RaRhAeu <rarha_eu@protonmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/51/fd/1313078f462a1712aee50bd5d1674de78fe3b1d5c48d5feab3e9d122139d/redguard-0.1.0.tar.gz",
    "platform": null,
    "description": "![Tests](https://github.com/asynq-io/redguard/workflows/Tests/badge.svg)\n![Build](https://github.com/asynq-io/redguard/workflows/Publish/badge.svg)\n![License](https://img.shields.io/github/license/asynq-io/redguard)\n![Python](https://img.shields.io/pypi/pyversions/redguard)\n![Format](https://img.shields.io/pypi/format/redguard)\n![PyPi](https://img.shields.io/pypi/v/redguard)\n![Mypy](https://img.shields.io/badge/mypy-checked-blue)\n[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/charliermarsh/ruff/main/assets/badge/v1.json)](https://github.com/charliermarsh/ruff)\n[![security: bandit](https://img.shields.io/badge/security-bandit-yellow.svg)](https://github.com/PyCQA/bandit)\n\n# redguard\n\nDistributed synchronization primitives buit on top of Redis\n\n## Installation\n\n```shell\npip install redguard\n```\n\n## Available primitives\n\n- `Lock` - distributed mutex\n- `Semaphore` - distributed semaphore\n- `RateLimiter` - distributed rate limiter\n\n## Helpers\n\n- `RedGuard` - factory for creating primitives\n- `SharedResourcePool` - factory for creating shared resources\n\n## Usage\n\nThe api is similar to built-in `asyncio` module primitives.\n\n```python\nfrom redguard import RedGuard\nfrom redguard.lock import Lock\n\nguard = RedGuard.from_url(\"redis://localhost:6379\")\n\nasync def lock_example():\n    lock = guard.new(Lock, \"my-lock\")\n\n    async with lock:\n        print(\"Locked\")\n\nasync def semaphore_example():\n    semaphore = guard.new(Semaphore, \"my-semaphore\", capacity=2)\n\n    async with semaphore:\n        print(\"Acquired\")\n\nasync def rate_limiter_example():\n    rate_limiter = guard.new(RateLimiter, \"my-rate-limiter\", limit=2, window=1)\n\n    async with rate_limiter:\n        print(\"Rate limited\")\n\n```\n\n### Lower level api\n\nEach primitve can be used as async context manager, but also provides `acquire` and `release` methods.\n\n```python\n\nsemaphore = guard.new(Semaphore, \"my-semaphore\", capacity=2)\n\nacquired = await semaphore.acquire(blocking=True, timeout=None) # returns True if acquired (useful for blocking=False)\n\nif acquired:\n    await semaphore.release()\n\n```\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Distributed synchronization primitives buit on top of Redis",
    "version": "0.1.0",
    "project_urls": {
        "Documentation": "https://github.com/asynq-io/redguard#readme",
        "Issues": "https://github.com/asynq-io/redguard/issues",
        "Source": "https://github.com/asynq-io/redguard"
    },
    "split_keywords": [
        "distributed",
        " limiter",
        " lock",
        " mutex",
        " rate",
        " redis",
        " semaphore",
        " synchronization"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "9b8ddabc4c830109e4bedfbe28e1b3c0f1aedd0f98b82b7bea77f9da788b7cc1",
                "md5": "b7395c3dd24ad3653a0c17630be72c12",
                "sha256": "a4f945f2f1b0fc34f4cab3001a7659171731120a9f6f4fd350aad1be0f6fd1ed"
            },
            "downloads": -1,
            "filename": "redguard-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "b7395c3dd24ad3653a0c17630be72c12",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 11607,
            "upload_time": "2025-02-16T21:39:21",
            "upload_time_iso_8601": "2025-02-16T21:39:21.589435Z",
            "url": "https://files.pythonhosted.org/packages/9b/8d/dabc4c830109e4bedfbe28e1b3c0f1aedd0f98b82b7bea77f9da788b7cc1/redguard-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "51fd1313078f462a1712aee50bd5d1674de78fe3b1d5c48d5feab3e9d122139d",
                "md5": "e47b6ef3849e15599dd1b288d533e50e",
                "sha256": "44713f09545023ae74b35ce6d3855e4b1143e6be56c0fe944d0ad098fe627775"
            },
            "downloads": -1,
            "filename": "redguard-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "e47b6ef3849e15599dd1b288d533e50e",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 10365,
            "upload_time": "2025-02-16T21:39:23",
            "upload_time_iso_8601": "2025-02-16T21:39:23.588580Z",
            "url": "https://files.pythonhosted.org/packages/51/fd/1313078f462a1712aee50bd5d1674de78fe3b1d5c48d5feab3e9d122139d/redguard-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-16 21:39:23",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "asynq-io",
    "github_project": "redguard#readme",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "redguard"
}
        
Elapsed time: 0.43524s