Catalog PyPI
PACKAGE EXPLORERView in registry

active-request

PyPI

Sliding-window active request counter (last 60s) using Redis for FastAPI or any Python app.

Versions collected1
Direct dependencies1From release 2025.9.152128
Last observed20 Oct, 18:36 UTC

README

Version 2025.9.152128 documentation

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.

Downloads & popularity

Awaiting observations

No metric observations yet

Download counts and popularity will appear here as the collector receives them.

Versions 1

Collected releases
VersionPublishedDirect dependenciesOpen version
2025.9.15212815 Sept 20251

Package advisories

0
No matching advisories collected

This describes our collected data; it is not a security assessment.

Repository

PENDING
chigwell/active_request

Shared repository data · GitHub

License detected in repository
Not collected

Metadata history

Meaningful changes
Current collected state Current

Observed since 20 Oct, 18:36 UTC

No superseded metadata states collected. Unchanged observations do not create new revisions.

Record identity

package:7a9203ab877731167e9945f2fcfba3682941ad50f22a2eef5fd37dba9a0973ca