proxywhirl.api.models¶
API-specific Pydantic models for REST API request/response validation.
This module contains models specific to the HTTP API layer, separate from core domain models in models.py. These models define the API contract including: - Generic response envelope (APIResponse[T]) - Error details and codes - Request/response metadata - API-specific entities (ProxyResource, etc.)
Classes¶
Generic envelope for all API responses. |
|
Response model for circuit breaker state change event. |
|
Response model for circuit breaker state. |
|
API configuration settings. |
|
Request to add a new proxy to the pool. |
|
Standard error codes for API responses. |
|
Structured error information for API responses. |
|
Response model for export history query. |
|
Request model for creating an export. |
|
Response model for export status query. |
|
Request to health check specific proxies. |
|
Result of a proxy health check. |
|
API health status response. |
|
Metadata included in all API responses. |
|
API performance metrics response. |
|
Paginated list response. |
|
Request to make an HTTP request through a proxy. |
|
Response from a proxied HTTP request. |
|
Per-proxy performance metrics. |
|
Statistics about the proxy pool. |
|
RESTful representation of a proxy in the pool. |
|
Per-proxy retry statistics. |
|
Response model for per-proxy retry statistics. |
|
Per-proxy statistics for metrics endpoints. |
|
Rate limiting configuration. |
|
API readiness status response. |
|
Response model for retry metrics summary. |
|
Request model for updating retry policy. |
|
Response model for retry policy. |
|
API and pool status response. |
|
Single data point in time-series metrics. |
|
Response model for time-series retry data. |
|
Request to update API configuration (partial updates allowed). |
Module Contents¶
- class proxywhirl.api.models.APIResponse(/, **data)[source]¶
Bases:
pydantic.BaseModel,Generic[T]Generic envelope for all API responses.
Provides consistent structure: - status: HTTP-like status indicator - data: Successful response payload (type T) - error: Error details if request failed - meta: Request metadata (ID, timestamp, version)
Example successful response:
{ "status": "success", "data": {"id": "123", "url": "http://proxy:8080"}, "error": null, "meta": {"request_id": "...", "timestamp": "...", "version": "1.0.0"} }
Example error response:
{ "status": "error", "data": null, "error": {"code": "PROXY_NOT_FOUND", "message": "...", ...}, "meta": {"request_id": "...", "timestamp": "...", "version": "1.0.0"} }
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- classmethod error_response(code, message, details=None, **kwargs)[source]¶
Create an error response with error details.
- Parameters:
- Returns:
APIResponse with status=’error’ and error populated
- Return type:
APIResponse[T]
- classmethod success(data, **kwargs)[source]¶
Create a successful response with data payload.
- Parameters:
data (T) – Response payload
**kwargs (Any) – Additional fields to override (e.g., meta)
- Returns:
APIResponse with status=’success’ and data populated
- Return type:
APIResponse[T]
- class proxywhirl.api.models.CircuitBreakerEventResponse(/, **data)[source]¶
Bases:
pydantic.BaseModelResponse model for circuit breaker state change event.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class proxywhirl.api.models.CircuitBreakerResponse(/, **data)[source]¶
Bases:
pydantic.BaseModelResponse model for circuit breaker state.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class proxywhirl.api.models.ConfigurationSettings(/, **data)[source]¶
Bases:
pydantic.BaseModelAPI configuration settings.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class proxywhirl.api.models.CreateProxyRequest(/, **data)[source]¶
Bases:
pydantic.BaseModelRequest to add a new proxy to the pool.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- classmethod validate_proxy_url(v)[source]¶
Validate proxy URL scheme, port, and length.
- Parameters:
v (str) – Proxy URL to validate
- Returns:
Validated URL
- Raises:
ValueError – If URL is invalid
- Return type:
- classmethod validate_username(v)[source]¶
Validate username length.
- Parameters:
v (str | None) – Username to validate
- Returns:
Validated username
- Raises:
ValueError – If username exceeds length limit
- Return type:
str | None
- class proxywhirl.api.models.ErrorCode[source]¶
-
Standard error codes for API responses.
Initialize self. See help(type(self)) for accurate signature.
- class proxywhirl.api.models.ErrorDetail(/, **data)[source]¶
Bases:
pydantic.BaseModelStructured error information for API responses.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class proxywhirl.api.models.ExportHistoryResponse(/, **data)[source]¶
Bases:
pydantic.BaseModelResponse model for export history query.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class proxywhirl.api.models.ExportRequest(/, **data)[source]¶
Bases:
pydantic.BaseModelRequest model for creating an export.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class proxywhirl.api.models.ExportStatusResponse(/, **data)[source]¶
Bases:
pydantic.BaseModelResponse model for export status query.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class proxywhirl.api.models.HealthCheckRequest(/, **data)[source]¶
Bases:
pydantic.BaseModelRequest to health check specific proxies.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class proxywhirl.api.models.HealthCheckResult(/, **data)[source]¶
Bases:
pydantic.BaseModelResult of a proxy health check.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class proxywhirl.api.models.HealthResponse(/, **data)[source]¶
Bases:
pydantic.BaseModelAPI health status response.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class proxywhirl.api.models.MetaInfo(/, **data)[source]¶
Bases:
pydantic.BaseModelMetadata included in all API responses.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class proxywhirl.api.models.MetricsResponse(/, **data)[source]¶
Bases:
pydantic.BaseModelAPI performance metrics response.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class proxywhirl.api.models.PaginatedResponse(/, **data)[source]¶
Bases:
pydantic.BaseModel,Generic[T]Paginated list response.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class proxywhirl.api.models.ProxiedRequest(/, **data)[source]¶
Bases:
pydantic.BaseModelRequest to make an HTTP request through a proxy.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- classmethod validate_body(v)[source]¶
Validate body length.
- Parameters:
v (str | None) – Body string to validate
- Returns:
Validated body
- Raises:
ValueError – If body exceeds length limit
- Return type:
str | None
- classmethod validate_url_scheme(v)[source]¶
Validate that URL uses http or https scheme only.
- Parameters:
v (pydantic.HttpUrl) – URL to validate
- Returns:
Validated URL
- Raises:
ValueError – If URL scheme is not http or https
- Return type:
- class proxywhirl.api.models.ProxiedResponse(/, **data)[source]¶
Bases:
pydantic.BaseModelResponse from a proxied HTTP request.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class proxywhirl.api.models.ProxyMetrics(/, **data)[source]¶
Bases:
pydantic.BaseModelPer-proxy performance metrics.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class proxywhirl.api.models.ProxyPoolStats(/, **data)[source]¶
Bases:
pydantic.BaseModelStatistics about the proxy pool.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class proxywhirl.api.models.ProxyResource(/, **data)[source]¶
Bases:
pydantic.BaseModelRESTful representation of a proxy in the pool.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class proxywhirl.api.models.ProxyRetryStats(/, **data)[source]¶
Bases:
pydantic.BaseModelPer-proxy retry statistics.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class proxywhirl.api.models.ProxyRetryStatsResponse(/, **data)[source]¶
Bases:
pydantic.BaseModelResponse model for per-proxy retry statistics.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class proxywhirl.api.models.ProxyStats(/, **data)[source]¶
Bases:
pydantic.BaseModelPer-proxy statistics for metrics endpoints.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class proxywhirl.api.models.RateLimitConfig(/, **data)[source]¶
Bases:
pydantic.BaseModelRate limiting configuration.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class proxywhirl.api.models.ReadinessResponse(/, **data)[source]¶
Bases:
pydantic.BaseModelAPI readiness status response.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class proxywhirl.api.models.RetryMetricsResponse(/, **data)[source]¶
Bases:
pydantic.BaseModelResponse model for retry metrics summary.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class proxywhirl.api.models.RetryPolicyRequest(/, **data)[source]¶
Bases:
pydantic.BaseModelRequest model for updating retry policy.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class proxywhirl.api.models.RetryPolicyResponse(/, **data)[source]¶
Bases:
pydantic.BaseModelResponse model for retry policy.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class proxywhirl.api.models.StatusResponse(/, **data)[source]¶
Bases:
pydantic.BaseModelAPI and pool status response.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class proxywhirl.api.models.TimeSeriesDataPoint(/, **data)[source]¶
Bases:
pydantic.BaseModelSingle data point in time-series metrics.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class proxywhirl.api.models.TimeSeriesResponse(/, **data)[source]¶
Bases:
pydantic.BaseModelResponse model for time-series retry data.
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- class proxywhirl.api.models.UpdateConfigRequest(/, **data)[source]¶
Bases:
pydantic.BaseModelRequest to update API configuration (partial updates allowed).
Create a new model by parsing and validating input data from keyword arguments.
Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.
self is explicitly positional-only to allow self as a field name.
- Parameters:
data (Any)
- classmethod validate_cors_origins(v)[source]¶
Validate CORS origins length.
- Parameters:
- Returns:
Validated CORS origins
- Raises:
ValueError – If any origin exceeds length limit
- Return type:
- classmethod validate_rotation_strategy(v)[source]¶
Validate rotation strategy is from allowed set.
- Parameters:
v (str | None) – Rotation strategy to validate
- Returns:
Validated rotation strategy
- Raises:
ValueError – If rotation strategy is invalid
- Return type:
str | None