Metadata-Version: 2.5
Name: rateguard-sdk
Version: 0.1.0
Summary: Tiny Python client for RateGuard
Project-URL: Homepage, https://github.com/faizahmd2/rate-guard-sdk
Project-URL: Repository, https://github.com/faizahmd2/rate-guard-sdk
Author: Faiz Ahmad
License-Expression: MIT
Keywords: api,rate-limit,rate-limiting,rateguard,sdk
Classifier: Development Status :: 3 - Alpha
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Requires-Python: >=3.10
Description-Content-Type: text/markdown

# rateguard-sdk

Tiny Python client for [RateGuard](https://github.com/faizahmd2/rate-limitter-service).

RateGuard is a centralized API rate-limiting service.

## Installation

```bash
pip install rateguard-sdk
```

## Usage

```python
from rateguard import CheckRequest, RateGuard

rate_guard = RateGuard(
    base_url="http://localhost:4215",
    token="rg_...",
)

decision = rate_guard.check(
    CheckRequest(
        service="payments",
        resource="create-payment",
        key="account:123",
    )
)

if decision.decision == "DENY":
    print(
        f"Rate limited. Retry after "
        f"{decision.retry_after_ms}ms"
    )
else:
    print("Request allowed")
```

## Configuration

```python
rate_guard = RateGuard(
    base_url="http://localhost:4215",
    token="rg_...",
)
```

### `base_url`

Base URL of the RateGuard server.

### `token`

API token generated by the RateGuard admin interface.

## Check Request

```python
CheckRequest(
    service="payments",
    resource="create-payment",
    key="account:123",
)
```

## Decision

```python
Decision(
    decision="ALLOW",
    limit=5,
    remaining=4,
    retry_after_ms=0,
)
```

When the decision is `DENY`, the application decides what to do next. The SDK does not automatically retry, queue, delay, or reject the application's request.

## Errors

Connection and HTTP failures raise `RateGuardError`.

```python
from rateguard import (
    CheckRequest,
    RateGuard,
    RateGuardError,
)

try:
    decision = rate_guard.check(
        CheckRequest(
            service="payments",
            resource="create-payment",
            key="account:123",
        )
    )

    if decision.decision == "DENY":
        print("Rate limited")

except RateGuardError as error:
    print(error)
```

## Requirements

* Python 3.10+
* A running RateGuard server

## License

MIT

```
```
