api_base
¶
Base classes and utilities for external API services.
This module provides common functionality for all API providers including: - Rate limiting with moving window approach - Common type definitions - Base scoring and normalization methods - Shared utilities for API interactions
ScoredRelease
¶
Bases: TypedDict
Type definition for a scored release with metadata and scoring details.
ApiRateLimiter
¶
Advanced rate limiter using a moving window approach for API calls.
This rate limiter tracks API calls within a sliding time window to ensure compliance with API rate limits. It uses a moving window algorithm that's more accurate than simple token bucket approaches.
Attributes:
| Name | Type | Description |
|---|---|---|
requests_per_window |
Maximum number of requests allowed in the time window |
|
window_seconds |
Size of the time window in seconds |
|
call_times |
list[float]
|
List of timestamps for recent API calls |
lock |
Asyncio lock for thread-safe operations |
Initialize the rate limiter.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
requests_per_window
|
int
|
Maximum requests allowed in the time window |
required |
window_seconds
|
float
|
Duration of the time window in seconds |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
If parameters are not positive numbers |
Source code in src/services/api/api_base.py
acquire
async
¶
Acquire permission to make an API call, waiting if necessary.
Returns:
| Type | Description |
|---|---|
float
|
The amount of time (in seconds) that was spent waiting |
Source code in src/services/api/api_base.py
release
¶
get_stats
¶
Get current rate limiter statistics.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing current stats and configuration |
Source code in src/services/api/api_base.py
BaseApiClient
¶
Base class for API client implementations.
Provides common functionality for all API clients including - Name normalization - Year validation - Common scoring logic
Initialize base API client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
console_logger
|
Logger
|
Logger for console output |
required |
error_logger
|
Logger
|
Logger for error messages |
required |