uniqc.network_utils module#
Network utilities for proxy detection and connectivity testing.
This module provides functions for: - Detecting system proxy settings - Testing proxy connectivity - Testing IBM Quantum connectivity with or without proxy
- uniqc.network_utils.check_proxy_connectivity(proxy_url, test_url='https://www.googleapis.com', timeout=10.0)[source]#
Check if a proxy is reachable and can connect to a test URL.
- Parameters:
proxy_url (str) – The proxy URL to test (e.g., ‘http://proxy.example.com:8080’).
test_url (str) – URL to test connectivity through the proxy (default: Google APIs).
timeout (float) – Connection timeout in seconds (default: 10.0).
- Returns:
True if the proxy is reachable, False otherwise.
- Return type:
Note
This function performs a basic TCP connection check to the proxy host and port. It does not perform an actual HTTP CONNECT request or verify that the proxy can reach the test URL.
Example
>>> is_available = check_proxy_connectivity( ... "http://proxy.example.com:8080" ... ) >>> print(f"Proxy available: {is_available}")
- uniqc.network_utils.detect_system_proxy()[source]#
Detect system proxy settings from environment variables.
Checks for both uppercase and lowercase environment variable names: - HTTP_PROXY / http_proxy - HTTPS_PROXY / https_proxy
Uppercase variants take precedence over lowercase ones.
- Returns:
dict with keys ‘http’ and ‘https’, values are proxy URLs or None.
- Return type:
Example
>>> proxies = detect_system_proxy() >>> print(proxies) {'http': 'http://proxy.example.com:8080', 'https': None}
- uniqc.network_utils.get_ibm_proxy_from_config(config=None)[source]#
Extract IBM proxy configuration from uniqc config.
- Parameters:
config (dict[str, Any] | None) – IBM configuration dict. If None, loads from uniqc config.
- Returns:
Dict with ‘http’ and/or ‘https’ proxy URLs, or None if no proxy configured.
- Return type:
Example
>>> from uniqc.config import get_ibm_config >>> config = get_ibm_config() >>> proxy = get_ibm_proxy_from_config(config)
- uniqc.network_utils.test_ibm_connectivity(token=None, proxy=None, timeout=30.0)[source]#
Test connectivity to IBM Quantum services.
- Parameters:
token (str | None) – IBM Quantum API token. If None, tries to load from environment.
proxy (dict[str, str] | str | None) – Proxy configuration. Can be: - None: uses system proxy settings - str: proxy URL (used for both http and https) - dict: with ‘http’ and/or ‘https’ keys
timeout (float) – Request timeout in seconds (default: 30.0).
- Returns:
success(bool)message(str)proxy_used(dict | str | None)response_time_ms(float | None)
- Return type:
dict with connectivity test results. Keys
Example
>>> result = test_ibm_connectivity( ... token="my_api_token", ... proxy={"https": "http://proxy.example.com:8080"} ... ) >>> print(result["success"])