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.151746

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.151746
File Size Uploaded
active_request-2025.9.151746.tar.gz 3.8 kB Details

Built distribution (wheel)

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

Total release size: 8.0 kB

Release files / active_request-2025.9.151746.tar.gz

Download URL active_request-2025.9.151746.tar.gz
Size 3.8 kB
Tags Source
SHA-256 checksum
How to use checksums
f1a3d8f6be22ef83e2341cac0bee289a6ff63cd123ccf35b0698d9a8216c883e
BLAKE2b-256 checksum
How to use checksums
387666605309abd1a9e34b3d31b15379e8aee72306b44d39a43458cbe6412d9f
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.151746-py3-none-any.whl

Download URL active_request-2025.9.151746-py3-none-any.whl
Size 4.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3fb7f750c99b1bd74b3c83bd91a4edc736f56fcc5ab4705385517b700ad20525
BLAKE2b-256 checksum
How to use checksums
4a8f2184906655ced1b684970c49d85e2e52bb15d7552b3d09ff475379c90b29
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.151746 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