Metadata-Version: 2.4
Name: traffik
Version: 1.1.0
Summary: Asynchronous distributed rate limiting for FastAPI/Starlette applications.
Project-URL: Homepage, https://github.com/ti-oluwa/traffik
Project-URL: Documentation, https://ti-oluwa.github.io/traffik/
Project-URL: Repository, https://github.com/ti-oluwa/traffik.git
Project-URL: Bug Tracker, https://github.com/ti-oluwa/traffik/issues
Project-URL: Changelog, https://github.com/ti-oluwa/traffik/blob/main/CHANGELOG.md
Author-email: tioluwa <tioluwa.dev@gmail.com>
Maintainer-email: tioluwa <tioluwa.dev@gmail.com>
License: MIT License
        
        Copyright (c) 2025 Daniel T. Afolayan 
        
        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
Keywords: api,async,asyncio,distributed,distributed-rate-limiting,fastapi,memcached,middleware,rate-limiter,rate-limiting,redis,starlette,throttling,websocket
Classifier: Development Status :: 5 - Production/Stable
Classifier: Framework :: AsyncIO
Classifier: Framework :: FastAPI
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.9
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: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: System :: Networking
Requires-Python: >=3.9
Requires-Dist: annotated-types>=0.7.0
Requires-Dist: msgpack>=1.1.2
Requires-Dist: starlette>=0.14.0
Provides-Extra: all
Requires-Dist: aiomcache>=0.8.2; extra == 'all'
Requires-Dist: pottery>=3.0.1; extra == 'all'
Requires-Dist: redis>=5.0.0; extra == 'all'
Provides-Extra: benchmark
Requires-Dist: aiomcache>=0.8.2; extra == 'benchmark'
Requires-Dist: anyio>=4.0.0; extra == 'benchmark'
Requires-Dist: bandit>=1.7.10; extra == 'benchmark'
Requires-Dist: fastapi>=0.68.0; extra == 'benchmark'
Requires-Dist: httpx>=0.28.0; extra == 'benchmark'
Requires-Dist: line-profiler>=5.0.0; extra == 'benchmark'
Requires-Dist: memory-profiler>=0.61.0; extra == 'benchmark'
Requires-Dist: mypy>=1.14.1; extra == 'benchmark'
Requires-Dist: pottery>=3.0.1; extra == 'benchmark'
Requires-Dist: psutil>=5.9.5; extra == 'benchmark'
Requires-Dist: pymemcache>=4.0.0; extra == 'benchmark'
Requires-Dist: pytest-asyncio>=0.24.0; extra == 'benchmark'
Requires-Dist: pytest-cov>=5.0.0; extra == 'benchmark'
Requires-Dist: pytest-rerunfailures>=16.0.1; extra == 'benchmark'
Requires-Dist: pytest-watch>=4.2.0; extra == 'benchmark'
Requires-Dist: pytest>=8.0.0; extra == 'benchmark'
Requires-Dist: redis>=5.0.0; extra == 'benchmark'
Requires-Dist: requests>=2.32.4; extra == 'benchmark'
Requires-Dist: ruff>=0.12.1; extra == 'benchmark'
Requires-Dist: slowapi>=0.1.4; extra == 'benchmark'
Requires-Dist: uvicorn>=0.22.0; extra == 'benchmark'
Provides-Extra: dev
Requires-Dist: aiomcache>=0.8.2; extra == 'dev'
Requires-Dist: anyio>=4.0.0; extra == 'dev'
Requires-Dist: bandit>=1.7.10; extra == 'dev'
Requires-Dist: fastapi>=0.68.0; extra == 'dev'
Requires-Dist: httpx>=0.28.0; extra == 'dev'
Requires-Dist: mypy>=1.14.1; extra == 'dev'
Requires-Dist: pottery>=3.0.1; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.24.0; extra == 'dev'
Requires-Dist: pytest-cov>=5.0.0; extra == 'dev'
Requires-Dist: pytest-rerunfailures>=16.0.1; extra == 'dev'
Requires-Dist: pytest-watch>=4.2.0; extra == 'dev'
Requires-Dist: pytest>=8.0.0; extra == 'dev'
Requires-Dist: redis>=5.0.0; extra == 'dev'
Requires-Dist: requests>=2.32.4; extra == 'dev'
Requires-Dist: ruff>=0.12.1; extra == 'dev'
Provides-Extra: docs
Requires-Dist: mkdocs-material>=9.5.0; extra == 'docs'
Requires-Dist: mkdocs-minify-plugin>=0.8.0; extra == 'docs'
Requires-Dist: pymdown-extensions>=10.0.0; extra == 'docs'
Provides-Extra: memcached
Requires-Dist: aiomcache>=0.8.2; extra == 'memcached'
Provides-Extra: redis
Requires-Dist: pottery>=3.0.1; extra == 'redis'
Requires-Dist: redis>=5.0.0; extra == 'redis'
Provides-Extra: test
Requires-Dist: aiomcache>=0.8.2; extra == 'test'
Requires-Dist: anyio>=4.0.0; extra == 'test'
Requires-Dist: fastapi>=0.68.0; extra == 'test'
Requires-Dist: httpx>=0.28.0; extra == 'test'
Requires-Dist: pottery>=3.0.1; extra == 'test'
Requires-Dist: pytest-asyncio>=0.24.0; extra == 'test'
Requires-Dist: pytest-cov>=5.0.0; extra == 'test'
Requires-Dist: pytest-rerunfailures>=16.0.1; extra == 'test'
Requires-Dist: pytest>=8.0.0; extra == 'test'
Requires-Dist: redis>=5.0.0; extra == 'test'
Requires-Dist: requests>=2.32.4; extra == 'test'
Description-Content-Type: text/markdown

# Traffik

Asynchronous distributed rate limiting for FastAPI/Starlette applications.

[![Test](https://github.com/ti-oluwa/traffik/actions/workflows/test.yaml/badge.svg)](https://github.com/ti-oluwa/traffik/actions/workflows/test.yaml)
[![Code Quality](https://github.com/ti-oluwa/traffik/actions/workflows/code-quality.yaml/badge.svg)](https://github.com/ti-oluwa/traffik/actions/workflows/code-quality.yaml)
[![codecov](https://codecov.io/gh/ti-oluwa/traffik/branch/main/graph/badge.svg)](https://codecov.io/gh/ti-oluwa/traffik)
[![PyPI version](https://badge.fury.io/py/traffik.svg)](https://badge.fury.io/py/traffik)
[![Python versions](https://img.shields.io/pypi/pyversions/traffik.svg)](https://pypi.org/project/traffik/)

## Features

- **Fully Asynchronous**: Built for async/await with non-blocking operations and minimal overhead
- **Distributed-First**: Atomic operations with distributed locks (Redis, Memcached) achieving high accuracy under concurrency
- **10+ Strategies**: Fixed Window, Sliding Window (Log & Counter), Token Bucket, Leaky Bucket, GCRA, and more
- **HTTP & WebSocket**: Full-featured rate limiting for both protocols with per-message throttling support
- **Production-Ready**: Circuit breakers, automatic retries, backend failover, and custom error handling
- **Flexible Integration**: Dependencies, decorators, middleware, or direct calls — use what fits your architecture
- **Highly Extensible**: Simple, well-documented APIs for custom backends, strategies, error handlers, and identifiers
- **Observable**: Rich error context and strategy statistics for monitoring
- **Performance-Optimized**: Lock striping, connection pooling, script caching, and minimal memory footprint

**Built for production workloads.**

## Documentation

Full documentation is available at **[https://ti-oluwa.github.io/traffik/](https://ti-oluwa.github.io/traffik/)**, covering:

- [Getting Started](https://ti-oluwa.github.io/traffik/quickstart/) - up and running in minutes
- [Core Concepts](https://ti-oluwa.github.io/traffik/core-concepts/) - backends, strategies, identifiers, rate formats
- [Integration](https://ti-oluwa.github.io/traffik/integration/) - dependencies, decorators, middleware, direct usage
- [Advanced Features](https://ti-oluwa.github.io/traffik/advanced/) - response headers, throttle rules, quota contexts, and more
- [Configuration](https://ti-oluwa.github.io/traffik/configuration/) - lock settings, environment variables
- [Error Handling](https://ti-oluwa.github.io/traffik/error-handling/) - retries, circuit breakers, fallbacks
- [Extending Traffik](https://ti-oluwa.github.io/traffik/extending/backends/) - custom backends and strategies
- [Testing](https://ti-oluwa.github.io/traffik/testing/) - patterns for testing throttled endpoints
- [Benchmarks](https://ti-oluwa.github.io/traffik/benchmarks/) - performance comparisons

## Installation

```bash
# Basic (InMemory backend only)
pip install traffik

# With Redis support
pip install "traffik[redis]"

# With Memcached support
pip install "traffik[memcached]"

# All backends
pip install "traffik[all]"
```

## Quick Start

```python
from fastapi import FastAPI, Depends
from traffik import HTTPThrottle
from traffik.backends.inmemory import InMemoryBackend

backend = InMemoryBackend(namespace="myapp")
app = FastAPI(lifespan=backend.lifespan)

throttle = HTTPThrottle("api:v1", rate="100/min", backend=backend)

@app.get("/items", dependencies=[Depends(throttle)])
async def list_items():
    return {"items": []}
```

See the [Quick Start guide](https://ti-oluwa.github.io/traffik/quickstart/) for more examples including Redis, WebSocket throttling, middleware setup, and advanced patterns.

## License

MIT — see [LICENSE](LICENSE) for details.
