rate_limiter
¶
AppleScript rate limiter module.
This module provides rate limiting for AppleScript execution using a moving window approach with concurrency control.
RateLimiterStats
¶
Bases: TypedDict
Statistics from the AppleScript rate limiter.
AppleScriptRateLimiter
¶
Advanced rate limiter using a moving window approach.
Initialize the rate limiter with configurable limits.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
requests_per_window
|
int
|
Maximum requests allowed per time window. |
required |
window_seconds
|
float
|
Duration of the sliding window in seconds. |
required |
max_concurrent
|
int
|
Maximum concurrent requests (semaphore limit). |
3
|
logger
|
Logger | None
|
Optional logger instance for debug output. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If any numeric parameter is not positive. |
Source code in src/services/apple/rate_limiter.py
initialize
async
¶
Initialize the rate limiter for async operation.
Creates the asyncio semaphore for concurrency control. Must be called before using acquire/release in an async context.
Source code in src/services/apple/rate_limiter.py
acquire
async
¶
Acquire permission to make a request.
Waits if necessary to respect rate limits, then acquires the semaphore. Records the request timestamp for sliding window calculation.
Returns:
| Type | Description |
|---|---|
float
|
Wait time in seconds (0.0 if no wait was needed). |
Source code in src/services/apple/rate_limiter.py
release
¶
Release the semaphore after request completion.
Should be called after each request finishes to allow other concurrent requests to proceed.
Source code in src/services/apple/rate_limiter.py
get_stats
¶
Get current rate limiter statistics.
Returns:
| Type | Description |
|---|---|
RateLimiterStats
|
Dictionary containing: |
RateLimiterStats
|
|
RateLimiterStats
|
|
RateLimiterStats
|
|
RateLimiterStats
|
|
RateLimiterStats
|
|
RateLimiterStats
|
|