Metadata-Version: 2.4
Name: coredis-utils
Version: 0.1.0
Summary: A collection of helpful utilities for coredis.
Project-URL: Homepage, https://github.com/tastyware/coredis-utils
Project-URL: Funding, https://github.com/sponsors/tastyware
Project-URL: Source, https://github.com/tastyware/coredis-utils
Project-URL: Changelog, https://github.com/tastyware/coredis-utils/releases
Author-email: Graeme Holliday <graeme@tastyware.dev>
License: MIT License
        
        Copyright (c) 2026 tastyware
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in all
        copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
        SOFTWARE.
License-File: LICENSE
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Framework :: AnyIO
Classifier: Framework :: AsyncIO
Classifier: Framework :: Django
Classifier: Framework :: FastAPI
Classifier: Framework :: Flask
Classifier: Framework :: Trio
Classifier: Intended Audience :: Developers
Classifier: Intended Audience :: Information Technology
Classifier: Intended Audience :: System Administrators
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: MacOS :: MacOS X
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: POSIX :: Linux
Classifier: Operating System :: Unix
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: System :: Clustering
Classifier: Topic :: System :: Distributed Computing
Classifier: Topic :: System :: Monitoring
Classifier: Topic :: System :: Systems Administration
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: coredis>=6.6.1
Description-Content-Type: text/markdown

[![PyPI](https://img.shields.io/pypi/v/coredis-utils)](https://pypi.org/project/coredis-utils)
[![Downloads](https://static.pepy.tech/badge/coredis-utils)](https://pepy.tech/project/coredis-utils)
[![Release](https://img.shields.io/github/v/release/tastyware/coredis-utils?label=release%20notes)](https://github.com/tastyware/coredis-utils/releases)

# coredis-utils

A collection of helpful utilities for [coredis](https://coredis.readthedocs.io/en/latest/).

## Features

- Caching decorator with thundering herd protection and error caching
- Idempotency keys
- Fixed-window rate limiting

## Installation

```console
$ pip install coredis-utils
```

## Getting started

First, create a `CoredisUtils` object wrapping a `coredis.Redis` instance:

```python
from coredis import Redis
from coredis_utils import CoredisUtils

client = Redis(...)
utils = CoredisUtils(client)
```

Caching is implemented with a decorator:

```python
@utils.cached(ttl=60)
async def my_task() -> int: ...
```

Idempotency uses a simple check:

```python
if await utils.idempotent("my-key", ttl=60):
    ...  # code in this block can only run once
```

Rate limiting is similar:

```python
for _ in range(15):
    print(await utils.limit("my-ip-addr", 10, 1))  # limit to 10/second
```

```python
True
True
True
True
True
True
True
True
True
True
False
False
False
False
False
```
