Metadata-Version: 2.4
Name: ratelimits
Version: 0.1.2
Summary: A simple function decorator that enables rate limiting using fixed window or sliding window strategies.
Author-email: Juan Carlos Largo <juanca.buy@gmail.com>
License: MIT License
        
        Copyright (c) 2025 Juanca LC
        
        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.
        
Project-URL: Homepage, https://github.com/Juancaa/ratelimiter
Project-URL: Issues, https://github.com/Juancaa/ratelimiter/issues
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

# ratelimiter

A small Python library that provides simple function decorators for rate limiting using either a fixed-window (bursty) or a sliding-window (steady) strategy.


Example — Fixed window (bursty)
```
from ratelimits import ratelimits
from concurrent.futures import ThreadPoolExecutor
from datetime import datetime as dt

@ratelimits("fixed_window", calls=10, period=20)
def my_task(x):
    print(f"[{dt.now()}] task", x)

with ThreadPoolExecutor(max_workers=None) as executor:
    executor.map(my_task, range(20))
```

Example — Sliding window (steady, evenly spaced)
```
from ratelimits import ratelimits
from concurrent.futures import ThreadPoolExecutor
from datetime import datetime as dt

@ratelimits("sliding_window", calls=10, period=20)
def my_task(x):
    print(f"[{dt.now()}] task", x)

with ThreadPoolExecutor(max_workers=None) as executor:
    executor.map(my_task, range(20))
```

### Parameters Summary

| Parameter | Type | Description |
|------------|------|-------------|
| **calls** | `int` | Maximum number of calls allowed per window. |
| **period** | `int` \| `float` | Duration of the window in seconds. |
| **offset_start** / **offset_end** | *(FixedWindow only)* | Optional adjustments for the start and end edges of the window. |
| **debug** | `bool` | Enables verbose logging to stdout for debugging and tracing sleep intervals. |
