Implementation:0xSteph Pentest ai RateLimiter
| Knowledge Sources | |
|---|---|
| Domains | Rate_Limiting, Scan_Intensity, Throttling |
| Last Updated | 2026-10-23 00:00 GMT |
Overview
Concrete tool for controlling scan intensity via per-intensity rate profiles with RPS, concurrency, and phase delays, provided by the pentest-ai engine.
Description
The rate_limiter module defines ScanProfile dataclass and RateLimiter class. ScanProfile.from_intensity maps intensity levels (stealth, safe, normal, aggressive) to rate profiles: requests_per_second, max_concurrent_tools, delay_between_phases, tool_timeout_seconds, and max_retries. The RateLimiter enforces the profile using asyncio semaphore and sleep.
Usage
Import this module when you need to throttle scan traffic or control tool concurrency. Used by the orchestrator and agent loop.
Code Reference
Source Location
- Repository: 0xSteph_Pentest_ai
- File: engine/rate_limiter.py
- Lines: 1-79
Signature
@dataclass(frozen=True)
class ScanProfile:
requests_per_second: float
max_concurrent_tools: int
delay_between_phases: float
tool_timeout_seconds: int
max_retries: int = 1
@classmethod
def from_intensity(cls, intensity: str) -> "ScanProfile": ...
class RateLimiter:
def __init__(self, profile: ScanProfile) -> None: ...
async def acquire(self) -> None: ...
async def release(self) -> None: ...
Import
from engine.rate_limiter import ScanProfile, RateLimiter
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| intensity | str | Yes | "stealth", "safe", "normal", or "aggressive" |
Outputs
| Name | Type | Description |
|---|---|---|
| ScanProfile | dataclass | Frozen rate profile for the intensity level |
Usage Examples
Apply Rate Limiting
import asyncio
from engine.rate_limiter import ScanProfile, RateLimiter
profile = ScanProfile.from_intensity("stealth")
# 2 RPS, 1 concurrent tool, 5s phase delay, 300s timeout, 0 retries
limiter = RateLimiter(profile)
async def scan():
await limiter.acquire()
try:
# ... run scan tool ...
pass
finally:
await limiter.release()
asyncio.run(scan())