Transport
provide.foundation.transport
¶
TODO: Add module docstring.
Classes¶
HTTPConfig
¶
HTTPResponseError
¶
Bases: TransportError
HTTP response error (4xx/5xx status codes).
Source code in provide/foundation/transport/errors.py
HTTPTransport
¶
Bases: TransportBase
HTTP/HTTPS transport using httpx backend.
Source code in provide/foundation/transport/base.py
Functions¶
connect
async
¶
Initialize httpx client with configuration.
Source code in provide/foundation/transport/http.py
disconnect
async
¶
execute
async
¶
Execute HTTP request.
Source code in provide/foundation/transport/http.py
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
stream
async
¶
Stream HTTP response.
Source code in provide/foundation/transport/http.py
supports
¶
LoggingMiddleware
¶
Bases: Middleware
Built-in telemetry middleware using foundation.logger.
Functions¶
process_error
async
¶
Log errors.
Source code in provide/foundation/transport/middleware.py
process_request
async
¶
Log outgoing request.
Source code in provide/foundation/transport/middleware.py
process_response
async
¶
Log incoming response.
Source code in provide/foundation/transport/middleware.py
MetricsMiddleware
¶
Bases: Middleware
Middleware for collecting transport metrics using foundation.metrics.
Functions¶
__attrs_post_init__
¶
Initialize metrics after creation.
Source code in provide/foundation/transport/middleware.py
process_error
async
¶
Record error metrics.
Source code in provide/foundation/transport/middleware.py
process_request
async
¶
process_response
async
¶
Record response metrics.
Source code in provide/foundation/transport/middleware.py
Middleware
¶
MiddlewarePipeline
¶
Pipeline for executing middleware in order.
Functions¶
add
¶
process_error
async
¶
Process error through all middleware.
process_request
async
¶
Process request through all middleware.
process_response
async
¶
Process response through all middleware (in reverse order).
Source code in provide/foundation/transport/middleware.py
remove
¶
Remove middleware by class type.
Source code in provide/foundation/transport/middleware.py
Request
¶
Response
¶
RetryMiddleware
¶
Bases: Middleware
Automatic retry middleware using unified retry logic.
Functions¶
execute_with_retry
async
¶
execute_with_retry(
execute_func: Callable[[Request], Awaitable[Response]],
request: Request,
) -> Response
Execute request with retry logic using unified RetryExecutor.
Source code in provide/foundation/transport/middleware.py
process_error
async
¶
Handle error, potentially with retries (this is called by client).
process_request
async
¶
process_response
async
¶
TransportConfig
¶
TransportConnectionError
¶
Bases: TransportError
Transport connection failed.
Source code in provide/foundation/transport/errors.py
TransportError
¶
TransportNotFoundError
¶
Bases: TransportError
No transport found for the given URI scheme.
Source code in provide/foundation/transport/errors.py
TransportTimeoutError
¶
Bases: TransportError
Transport request timed out.
Source code in provide/foundation/transport/errors.py
UniversalClient
¶
Universal client that works with any transport via Hub registry.
The client uses a TransportCache that automatically evicts transports that exceed the failure threshold (default: 3 consecutive failures).
Functions¶
__aenter__
async
¶
__aexit__
async
¶
__aexit__(
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: Any,
) -> None
Context manager exit - cleanup all transports.
Source code in provide/foundation/transport/client.py
delete
async
¶
get
async
¶
head
async
¶
options
async
¶
patch
async
¶
post
async
¶
put
async
¶
request
async
¶
request(
uri: str,
method: str | HTTPMethod = HTTPMethod.GET,
*,
headers: Headers | None = None,
params: Params | None = None,
body: Data = None,
timeout: float | None = None,
**kwargs: Any
) -> Response
Make a request using appropriate transport.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
str
|
Full URI to make request to |
required |
method
|
str | HTTPMethod
|
HTTP method or protocol-specific method |
GET
|
headers
|
Headers | None
|
Request headers |
None
|
params
|
Params | None
|
Query parameters |
None
|
body
|
Data
|
Request body (dict for JSON, str/bytes for raw) |
None
|
timeout
|
float | None
|
Request timeout override |
None
|
**kwargs
|
Any
|
Additional request metadata |
{}
|
Returns:
| Type | Description |
|---|---|
Response
|
Response from the transport |
Source code in provide/foundation/transport/client.py
reset_transport_cache
¶
Reset the transport cache.
Useful for testing or forcing reconnection after configuration changes.
stream
async
¶
stream(
uri: str,
method: str | HTTPMethod = HTTPMethod.GET,
**kwargs: Any
) -> AsyncIterator[bytes]
Stream data from URI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
str
|
URI to stream from |
required |
method
|
str | HTTPMethod
|
HTTP method or protocol-specific method |
GET
|
**kwargs
|
Any
|
Additional request parameters |
{}
|
Yields:
| Type | Description |
|---|---|
AsyncIterator[bytes]
|
Chunks of response data |
Source code in provide/foundation/transport/client.py
Functions¶
create_default_pipeline
¶
create_default_pipeline(
enable_retry: bool = True,
enable_logging: bool = True,
enable_metrics: bool = True,
) -> MiddlewarePipeline
Create pipeline with default middleware.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
enable_retry
|
bool
|
Enable automatic retry middleware (default: True) |
True
|
enable_logging
|
bool
|
Enable request/response logging middleware (default: True) |
True
|
enable_metrics
|
bool
|
Enable metrics collection middleware (default: True) |
True
|
Returns:
| Type | Description |
|---|---|
MiddlewarePipeline
|
Configured middleware pipeline |
Source code in provide/foundation/transport/middleware.py
delete
async
¶
get
async
¶
get_default_client
¶
Get or create the default client instance.
This function acts as the composition root for the default client, preserving backward compatibility for public convenience functions.
Source code in provide/foundation/transport/client.py
get_transport
¶
Get transport instance for a URI.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
uri
|
str
|
Full URI to get transport for |
required |
Returns:
| Type | Description |
|---|---|
Transport
|
Transport instance ready to use |
Raises:
| Type | Description |
|---|---|
TransportNotFoundError
|
If no transport supports the URI scheme |
Source code in provide/foundation/transport/registry.py
get_transport_info
¶
Get detailed information about a transport.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
scheme_or_name
|
str
|
URI scheme or transport name |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any] | None
|
Transport information or None if not found |
Source code in provide/foundation/transport/registry.py
head
async
¶
list_registered_transports
¶
List all registered transports.
Returns:
| Type | Description |
|---|---|
dict[str, dict[str, Any]]
|
Dictionary mapping transport names to their info |
Source code in provide/foundation/transport/registry.py
options
async
¶
patch
async
¶
post
async
¶
put
async
¶
register_transport
¶
register_transport(
transport_type: TransportType,
transport_class: type[Transport],
schemes: list[str] | None = None,
**metadata: Any
) -> None
Register a transport implementation in the Hub.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
transport_type
|
TransportType
|
The primary transport type |
required |
transport_class
|
type[Transport]
|
Transport implementation class |
required |
schemes
|
list[str] | None
|
List of URI schemes this transport handles |
None
|
**metadata
|
Any
|
Additional metadata for the transport |
{}
|
Source code in provide/foundation/transport/registry.py
request
async
¶
Make a request using the default client.
stream
async
¶
Stream data using default client.