HTTP Clients
HTTP client implementation for QLAM API communication.
HTTP clients for qlam-core.
This module provides thin wrappers around httpx that mirror the public API of
qlam_client while integrating with qlam-core's auth providers.
Autogeneration and OpenAPI linkage:
- Resource-specific plugins are backed by specs generated from OpenAPI
definitions. Those specs are consumed by
qlam_core.clients.http.universal_executor.execute_from_spec, which uses
these clients to perform requests. This file itself is hand-written but works
in concert with generated resource specs.
AuthenticatedClient
AuthenticatedClient(base_url: str, auth_provider: BaseAuthProvider, timeout: float | None = None, verify_ssl: bool | str = True, follow_redirects: bool = True, headers: Dict[str, str] | None = None, cookies: Dict[str, str] | None = None, logger: Logger | None = None)
Bases: Client
flowchart TD
qlam_core.clients.http.client.AuthenticatedClient[AuthenticatedClient]
qlam_core.clients.http.client.Client[Client]
qlam_core.clients.http.client.Client --> qlam_core.clients.http.client.AuthenticatedClient
click qlam_core.clients.http.client.AuthenticatedClient href "" "qlam_core.clients.http.client.AuthenticatedClient"
click qlam_core.clients.http.client.Client href "" "qlam_core.clients.http.client.Client"
HTTP client with authentication support.
Extends Client with authentication capabilities by integrating with auth providers that implement HTTPHeadersMixin. The auth provider is responsible for converting whatever authentication method it uses (tokens, credentials, etc.) into appropriate HTTP headers.
This design keeps the HTTP client focused purely on HTTP concerns while allowing auth providers to handle the specifics of their authentication method.
Initialize the authenticated HTTP client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_url
|
str
|
Base URL for API requests. |
required |
auth_provider
|
BaseAuthProvider
|
Auth provider (should implement HTTPHeadersMixin to provide authentication headers). |
required |
timeout
|
float | None
|
Request timeout in seconds. |
None
|
verify_ssl
|
bool | str
|
SSL verification (True, False, or path to CA bundle). |
True
|
follow_redirects
|
bool
|
Whether to follow HTTP redirects. |
True
|
headers
|
Dict[str, str] | None
|
Additional headers to include with requests. |
None
|
cookies
|
Dict[str, str] | None
|
Default cookies to include with requests. |
None
|
logger
|
Logger | None
|
Logger instance for debugging. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
Source code in qlam_core/clients/http/client.py
338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 | |
auth_provider
property
auth_provider: BaseAuthProvider
Get the authentication provider.
Returns:
| Type | Description |
|---|---|
BaseAuthProvider
|
Underlying auth provider instance. |
refresh_auth_headers
refresh_auth_headers() -> None
Refresh authentication headers from the provider.
This updates default headers with fresh authentication information from the auth provider. Useful when tokens may have been refreshed.
Source code in qlam_core/clients/http/client.py
520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 | |
with_cookies
with_cookies(cookies: Dict[str, str]) -> AuthenticatedClient
Return a new authenticated client with additional cookies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cookies
|
Dict[str, str]
|
Cookies to merge into defaults. |
required |
Returns:
| Type | Description |
|---|---|
AuthenticatedClient
|
A new |
Source code in qlam_core/clients/http/client.py
483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 | |
with_headers
with_headers(headers: Dict[str, str]) -> AuthenticatedClient
Return a new authenticated client with additional headers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
headers
|
Dict[str, str]
|
Headers to merge with fresh auth headers. |
required |
Returns:
| Type | Description |
|---|---|
AuthenticatedClient
|
A new |
Source code in qlam_core/clients/http/client.py
453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 | |
with_timeout
with_timeout(timeout: float) -> AuthenticatedClient
Return a new authenticated client with a different timeout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
float
|
New timeout value in seconds. |
required |
Returns:
| Type | Description |
|---|---|
AuthenticatedClient
|
A new |
Source code in qlam_core/clients/http/client.py
502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 | |
Client
Client(base_url: str, timeout: float | None = None, verify_ssl: bool | str = True, follow_redirects: bool = True, headers: Dict[str, str] | None = None, cookies: Dict[str, str] | None = None, logger: Logger | None = None)
HTTP client without authentication, mirroring qlam_client.Client API.
This client provides the same interface as qlam_client.Client but is designed for the QSH Client architecture. It requires explicit base_url configuration and fails fast if not properly configured.
Initialize the HTTP client.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
base_url
|
str
|
Base URL for API requests (required, fails fast if not set). |
required |
timeout
|
float | None
|
Request timeout in seconds. |
None
|
verify_ssl
|
bool | str
|
SSL verification (True, False, or path to CA bundle). |
True
|
follow_redirects
|
bool
|
Whether to follow HTTP redirects. |
True
|
headers
|
Dict[str, str] | None
|
Default headers to include with requests. |
None
|
cookies
|
Dict[str, str] | None
|
Default cookies to include with requests. |
None
|
logger
|
Logger | None
|
Logger instance for debugging. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If base_url is empty or None. |
Source code in qlam_core/clients/http/client.py
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 | |
base_url
property
base_url: str
Get the base URL.
Returns:
| Type | Description |
|---|---|
str
|
Base URL configured for the client. |
__aenter__
async
__aenter__() -> Client
Enter async context manager.
Returns:
| Type | Description |
|---|---|
Client
|
Self. |
Source code in qlam_core/clients/http/client.py
304 305 306 307 308 309 | |
__aexit__
async
__aexit__(exc_type: Type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None) -> None
Exit async context manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exc_type
|
Type[BaseException] | None
|
Exception type. |
required |
exc_val
|
BaseException | None
|
Exception value. |
required |
exc_tb
|
TracebackType | None
|
Exception traceback. |
required |
Source code in qlam_core/clients/http/client.py
311 312 313 314 315 316 317 318 319 320 321 322 323 | |
__enter__
__enter__() -> Client
Enter sync context manager.
Returns:
| Type | Description |
|---|---|
Client
|
Self. |
Source code in qlam_core/clients/http/client.py
283 284 285 286 287 288 | |
__exit__
__exit__(exc_type: Type[BaseException] | None, exc_val: BaseException | None, exc_tb: TracebackType | None) -> None
Exit sync context manager.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exc_type
|
Type[BaseException] | None
|
Exception type. |
required |
exc_val
|
BaseException | None
|
Exception value. |
required |
exc_tb
|
TracebackType | None
|
Exception traceback. |
required |
Source code in qlam_core/clients/http/client.py
290 291 292 293 294 295 296 297 298 299 300 301 302 | |
aclose
async
aclose() -> None
Close both sync and async httpx clients (async version).
Source code in qlam_core/clients/http/client.py
273 274 275 276 277 278 279 280 281 | |
close
close() -> None
Close both sync and async httpx clients.
Source code in qlam_core/clients/http/client.py
261 262 263 264 265 266 267 268 269 270 271 | |
get_async_httpx_client
get_async_httpx_client() -> httpx.AsyncClient
Get the underlying httpx.AsyncClient instance.
Returns:
| Type | Description |
|---|---|
AsyncClient
|
The configured |
Source code in qlam_core/clients/http/client.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 | |
get_httpx_client
get_httpx_client() -> httpx.Client
Get the underlying httpx.Client instance.
Returns:
| Type | Description |
|---|---|
Client
|
The configured |
Source code in qlam_core/clients/http/client.py
207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 | |
set_async_httpx_client
set_async_httpx_client(client: AsyncClient) -> None
Set a custom httpx.AsyncClient instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
AsyncClient
|
External |
required |
Source code in qlam_core/clients/http/client.py
250 251 252 253 254 255 256 257 258 259 | |
set_httpx_client
set_httpx_client(client: Client) -> None
Set a custom httpx.Client instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client
|
Client
|
External |
required |
Source code in qlam_core/clients/http/client.py
224 225 226 227 228 229 230 231 | |
with_cookies
with_cookies(cookies: Dict[str, str]) -> Client
Return a new client with additional cookies.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
cookies
|
Dict[str, str]
|
Cookies to merge into defaults. |
required |
Returns:
| Type | Description |
|---|---|
Client
|
A new |
Source code in qlam_core/clients/http/client.py
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
with_headers
with_headers(headers: Dict[str, str]) -> Client
Return a new client with additional headers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
headers
|
Dict[str, str]
|
Headers to merge into defaults. |
required |
Returns:
| Type | Description |
|---|---|
Client
|
A new |
Source code in qlam_core/clients/http/client.py
157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 | |
with_timeout
with_timeout(timeout: float) -> Client
Return a new client with a different timeout.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timeout
|
float
|
New timeout value in seconds. |
required |
Returns:
| Type | Description |
|---|---|
Client
|
A new |
Source code in qlam_core/clients/http/client.py
191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 | |
normalize_default_headers
normalize_default_headers(headers: Mapping[str, str] | None = None) -> Dict[str, str]
Apply the standard Accept and composed User-Agent headers.
Source code in qlam_core/clients/http/client.py
63 64 65 66 67 68 69 70 71 72 | |