active_request
active_request is a tiny Redis-backed sliding-window counter for tracking live requests in the last N seconds (default 60s). It is safe across multiple processes and works with both sync and async Redis clients (e.g. FastAPI).
Installation
pip install active_request
Requires Redis server and
redisPython client ≥ 5.0.
Usage
Sync
from __future__ import annotations
import os
import redis
from active_request import record_active_request
r = redis.Redis.from_url(os.getenv("REDIS_URL", "redis://localhost:6379/0"))
count = record_active_request(
r,
key="metrics:active_requests:api",
window_seconds=60,
gauge_key="metrics:active_requests:api:count",
)
print(count) # live number of requests in the last 60s
Async (FastAPI example)
from __future__ import annotations
import os
from fastapi import FastAPI, Depends
from redis.asyncio import Redis
from active_request import arecord_active_request
app = FastAPI()
redis_url = os.getenv("REDIS_URL", "redis://localhost:6379/0")
r = Redis.from_url(redis_url)
@app.get("/ping")
async def ping():
# Increment and get live count of requests in the last 60 seconds
live = await arecord_active_request(
r,
key="metrics:active_requests:api",
window_seconds=60,
gauge_key="metrics:active_requests:api:count",
)
return {"ok": True, "live_60s": live}
Features
- Sliding window counter using a Redis sorted set + Lua (accurate to milliseconds).
- Concurrency-safe across multiple workers/processes.
- Sync and async APIs:
record_active_request/arecord_active_request. - Optional “gauge” key written with short TTL for easy scraping/dashboards.
- Small dependency footprint (
redisonly).
Contributing
Contributions, issues, and feature requests are welcome! Repo: https://github.com/chigwell/active_request • Issues: https://github.com/chigwell/active_request/issues
License
active_request is licensed under the MIT License.
Metadata
Release files for active-request 2025.9.152128
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| active_request-2025.9.152128.tar.gz | 3.9 kB | Without provenance | Details for active_request-2025.9.152128.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| active_request-2025.9.152128-py3-none-any.whl | Python 3 | none | any | Details for active_request-2025.9.152128-py3-none-any.whl |
Total release size: 8.2 kB
Release files / active_request-2025.9.152128.tar.gz
| Download URL | active_request-2025.9.152128.tar.gz |
|---|---|
| Size | 3.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8c36439663fe28fba35971f1aabeba3dce082c728b0b5a7546bbe893144188a5
|
|
BLAKE2b-256 checksum How to use checksums |
9892f1a4307c021a65d4824b026751b9f17b91215db8c1af9032a4c1c355f0e8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.11
|
Release files / active_request-2025.9.152128-py3-none-any.whl
| Download URL | active_request-2025.9.152128-py3-none-any.whl |
|---|---|
| Size | 4.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
11820ec792b08f110d667e640fded2f85a1b5fec2fb6e0590746edae2ae4ba13
|
|
BLAKE2b-256 checksum How to use checksums |
9c5dfdc339032db904f47ea34f307d04017b959dd8d75853f3507e28f04571ed
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.11
|
Security for active-request 2025.9.152128
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.