Skip to main content

PyPI version License: MIT Downloads LinkedIn

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 redis Python 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 (redis only).

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)

Source distribution for active-request 2025.9.152128
File Size Uploaded
active_request-2025.9.152128.tar.gz 3.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for active-request 2025.9.152128
File Interpreter ABI Platform
active_request-2025.9.152128-py3-none-any.whl Python 3 none any Details

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

Release history Release notifications | RSS feed

This release

2025.9.152128 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page