|
| 1 | +# Proxy Configuration |
| 2 | + |
| 3 | +The Conductor Python SDK supports proxy configuration for both synchronous and asynchronous clients. This is useful when your application needs to route traffic through corporate firewalls, load balancers, or other network intermediaries. |
| 4 | + |
| 5 | +## Table of Contents |
| 6 | + |
| 7 | +- [Supported Proxy Types](#supported-proxy-types) |
| 8 | +- [Client Proxy Configuration](#client-proxy-configuration) |
| 9 | +- [Environment Variable Configuration](#environment-variable-configuration) |
| 10 | +- [Advanced Proxy Configuration](#advanced-proxy-configuration) |
| 11 | +- [Troubleshooting](#troubleshooting) |
| 12 | + |
| 13 | +## Supported Proxy Types |
| 14 | + |
| 15 | +- **HTTP Proxy**: `http://proxy.example.com:8080` |
| 16 | +- **HTTPS Proxy**: `https://proxy.example.com:8443` |
| 17 | +- **SOCKS4 Proxy**: `socks4://proxy.example.com:1080` |
| 18 | +- **SOCKS5 Proxy**: `socks5://proxy.example.com:1080` |
| 19 | +- **Proxy with Authentication**: `http://username:password@proxy.example.com:8080` |
| 20 | + |
| 21 | +> [!NOTE] |
| 22 | +> For SOCKS proxy support, install the additional dependency: `pip install httpx[socks]` |
| 23 | +
|
| 24 | +## Client Proxy Configuration |
| 25 | + |
| 26 | +### Basic HTTP Proxy Configuration |
| 27 | + |
| 28 | +```python |
| 29 | +from conductor.client.configuration.configuration import Configuration |
| 30 | +from conductor.shared.configuration.settings.authentication_settings import AuthenticationSettings |
| 31 | + |
| 32 | +# Basic HTTP proxy configuration |
| 33 | +config = Configuration( |
| 34 | + server_api_url="https://api.orkes.io/api", |
| 35 | + authentication_settings=AuthenticationSettings( |
| 36 | + key_id="your_key_id", |
| 37 | + key_secret="your_key_secret" |
| 38 | + ), |
| 39 | + proxy="http://proxy.company.com:8080" |
| 40 | +) |
| 41 | +``` |
| 42 | + |
| 43 | +### HTTPS Proxy with Authentication Headers |
| 44 | + |
| 45 | +```python |
| 46 | +# HTTPS proxy with authentication headers |
| 47 | +config = Configuration( |
| 48 | + server_api_url="https://api.orkes.io/api", |
| 49 | + authentication_settings=AuthenticationSettings( |
| 50 | + key_id="your_key_id", |
| 51 | + key_secret="your_key_secret" |
| 52 | + ), |
| 53 | + proxy="https://secure-proxy.company.com:8443", |
| 54 | + proxy_headers={ |
| 55 | + "Proxy-Authorization": "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", |
| 56 | + "X-Proxy-Client": "conductor-python-sdk" |
| 57 | + } |
| 58 | +) |
| 59 | +``` |
| 60 | + |
| 61 | +### SOCKS Proxy Configuration |
| 62 | + |
| 63 | +```python |
| 64 | +# SOCKS5 proxy configuration |
| 65 | +config = Configuration( |
| 66 | + server_api_url="https://api.orkes.io/api", |
| 67 | + proxy="socks5://proxy.company.com:1080" |
| 68 | +) |
| 69 | + |
| 70 | +# SOCKS5 proxy with authentication |
| 71 | +config = Configuration( |
| 72 | + server_api_url="https://api.orkes.io/api", |
| 73 | + proxy="socks5://username:password@proxy.company.com:1080" |
| 74 | +) |
| 75 | +``` |
| 76 | + |
| 77 | +## Environment Variable Configuration |
| 78 | + |
| 79 | +You can configure proxy settings using Conductor-specific environment variables: |
| 80 | + |
| 81 | +```shell |
| 82 | +# Basic proxy configuration |
| 83 | +export CONDUCTOR_PROXY=http://proxy.company.com:8080 |
| 84 | + |
| 85 | +# Proxy with authentication headers (JSON format) |
| 86 | +export CONDUCTOR_PROXY_HEADERS='{"Proxy-Authorization": "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", "X-Proxy-Client": "conductor-python-sdk"}' |
| 87 | + |
| 88 | +# Or single header value |
| 89 | +export CONDUCTOR_PROXY_HEADERS="Basic dXNlcm5hbWU6cGFzc3dvcmQ=" |
| 90 | +``` |
| 91 | + |
| 92 | +**Priority Order:** |
| 93 | +1. Explicit proxy parameters in Configuration constructor |
| 94 | +2. `CONDUCTOR_PROXY` and `CONDUCTOR_PROXY_HEADERS` environment variables |
| 95 | + |
| 96 | +### Example Usage with Environment Variables |
| 97 | + |
| 98 | +```python |
| 99 | +# Set environment variables |
| 100 | +import os |
| 101 | +os.environ['CONDUCTOR_PROXY'] = 'http://proxy.company.com:8080' |
| 102 | +os.environ['CONDUCTOR_PROXY_HEADERS'] = '{"Proxy-Authorization": "Basic dXNlcm5hbWU6cGFzc3dvcmQ="}' |
| 103 | + |
| 104 | +# Configuration will automatically use proxy from environment |
| 105 | +from conductor.client.configuration.configuration import Configuration |
| 106 | +config = Configuration(server_api_url="https://api.orkes.io/api") |
| 107 | +# Proxy is automatically configured from CONDUCTOR_PROXY environment variable |
| 108 | +``` |
| 109 | + |
| 110 | +## Advanced Proxy Configuration |
| 111 | + |
| 112 | +### Custom HTTP Client with Proxy |
| 113 | + |
| 114 | +```python |
| 115 | +import httpx |
| 116 | +from conductor.client.configuration.configuration import Configuration |
| 117 | + |
| 118 | +# Create custom HTTP client with proxy |
| 119 | +custom_client = httpx.Client( |
| 120 | + proxies={ |
| 121 | + "http://": "http://proxy.company.com:8080", |
| 122 | + "https://": "http://proxy.company.com:8080" |
| 123 | + }, |
| 124 | + timeout=httpx.Timeout(120.0), |
| 125 | + follow_redirects=True, |
| 126 | + limits=httpx.Limits(max_keepalive_connections=20, max_connections=100), |
| 127 | +) |
| 128 | + |
| 129 | +config = Configuration( |
| 130 | + server_api_url="https://api.orkes.io/api", |
| 131 | + http_connection=custom_client |
| 132 | +) |
| 133 | +``` |
| 134 | + |
| 135 | +### Proxy with Custom Headers |
| 136 | + |
| 137 | +```python |
| 138 | +import httpx |
| 139 | +from conductor.client.configuration.configuration import Configuration |
| 140 | + |
| 141 | +# Create custom HTTP client with proxy and headers |
| 142 | +custom_client = httpx.Client( |
| 143 | + proxies={ |
| 144 | + "http://": "http://proxy.company.com:8080", |
| 145 | + "https://": "http://proxy.company.com:8080" |
| 146 | + }, |
| 147 | + headers={ |
| 148 | + "Proxy-Authorization": "Basic dXNlcm5hbWU6cGFzc3dvcmQ=", |
| 149 | + "X-Proxy-Client": "conductor-python-sdk", |
| 150 | + "User-Agent": "Conductor-Python-SDK/1.0" |
| 151 | + } |
| 152 | +) |
| 153 | + |
| 154 | +config = Configuration( |
| 155 | + server_api_url="https://api.orkes.io/api", |
| 156 | + http_connection=custom_client |
| 157 | +) |
| 158 | +``` |
| 159 | + |
| 160 | +### SOCKS Proxy with Authentication |
| 161 | + |
| 162 | +```python |
| 163 | +import httpx |
| 164 | +from conductor.client.configuration.configuration import Configuration |
| 165 | + |
| 166 | +# SOCKS5 proxy with authentication |
| 167 | +custom_client = httpx.Client( |
| 168 | + proxies={ |
| 169 | + "http://": "socks5://username:password@proxy.company.com:1080", |
| 170 | + "https://": "socks5://username:password@proxy.company.com:1080" |
| 171 | + } |
| 172 | +) |
| 173 | + |
| 174 | +config = Configuration( |
| 175 | + server_api_url="https://api.orkes.io/api", |
| 176 | + http_connection=custom_client |
| 177 | +) |
| 178 | +``` |
| 179 | + |
| 180 | +### Async Client Proxy Configuration |
| 181 | + |
| 182 | +```python |
| 183 | +import asyncio |
| 184 | +import httpx |
| 185 | +from conductor.asyncio_client.configuration import Configuration |
| 186 | +from conductor.asyncio_client.adapters import ApiClient |
| 187 | + |
| 188 | +async def main(): |
| 189 | + # Create async HTTP client with proxy |
| 190 | + async_client = httpx.AsyncClient( |
| 191 | + proxies={ |
| 192 | + "http://": "http://proxy.company.com:8080", |
| 193 | + "https://": "http://proxy.company.com:8080" |
| 194 | + } |
| 195 | + ) |
| 196 | + |
| 197 | + config = Configuration( |
| 198 | + server_url="https://api.orkes.io/api", |
| 199 | + http_connection=async_client |
| 200 | + ) |
| 201 | + |
| 202 | + async with ApiClient(config) as api_client: |
| 203 | + # Use the client with proxy configuration |
| 204 | + pass |
| 205 | + |
| 206 | +asyncio.run(main()) |
| 207 | +``` |
| 208 | + |
| 209 | +## Troubleshooting |
| 210 | + |
| 211 | +### Common Proxy Issues |
| 212 | + |
| 213 | +1. **Connection refused** |
| 214 | + - Check if the proxy server is running |
| 215 | + - Verify the proxy URL and port |
| 216 | + - Check firewall settings |
| 217 | + |
| 218 | +2. **Authentication failed** |
| 219 | + - Verify username and password |
| 220 | + - Check if the proxy requires specific authentication method |
| 221 | + - Ensure credentials are properly encoded |
| 222 | + |
| 223 | +3. **SOCKS proxy not working** |
| 224 | + - Install httpx with SOCKS support: `pip install httpx[socks]` |
| 225 | + - Check if the SOCKS proxy server is accessible |
| 226 | + - Verify SOCKS version (4 or 5) |
| 227 | + |
| 228 | +4. **SSL/TLS issues through proxy** |
| 229 | + - Some proxies don't support HTTPS properly |
| 230 | + - Try using HTTP proxy for HTTPS traffic |
| 231 | + - Check proxy server SSL configuration |
| 232 | + |
| 233 | +### Debug Proxy Configuration |
| 234 | + |
| 235 | +```python |
| 236 | +import httpx |
| 237 | +import logging |
| 238 | + |
| 239 | +# Enable debug logging |
| 240 | +logging.basicConfig(level=logging.DEBUG) |
| 241 | + |
| 242 | +# Test proxy connection |
| 243 | +def test_proxy_connection(proxy_url): |
| 244 | + try: |
| 245 | + with httpx.Client(proxies={"http://": proxy_url, "https://": proxy_url}) as client: |
| 246 | + response = client.get("http://httpbin.org/ip") |
| 247 | + print(f"Proxy test successful: {response.json()}") |
| 248 | + except Exception as e: |
| 249 | + print(f"Proxy test failed: {e}") |
| 250 | + |
| 251 | +# Test your proxy |
| 252 | +test_proxy_connection("http://proxy.company.com:8080") |
| 253 | +``` |
| 254 | + |
| 255 | +### Proxy Environment Variables |
| 256 | + |
| 257 | +```bash |
| 258 | +# Set proxy environment variables for testing |
| 259 | +export HTTP_PROXY=http://proxy.company.com:8080 |
| 260 | +export HTTPS_PROXY=http://proxy.company.com:8080 |
| 261 | +export NO_PROXY=localhost,127.0.0.1 |
| 262 | + |
| 263 | +# Test with curl |
| 264 | +curl -I https://api.orkes.io/api |
| 265 | +``` |
| 266 | + |
| 267 | +### Proxy Authentication |
| 268 | + |
| 269 | +```python |
| 270 | +import base64 |
| 271 | +from urllib.parse import quote |
| 272 | + |
| 273 | +# Create proxy authentication header |
| 274 | +username = "your_username" |
| 275 | +password = "your_password" |
| 276 | +credentials = f"{username}:{password}" |
| 277 | +encoded_credentials = base64.b64encode(credentials.encode()).decode() |
| 278 | + |
| 279 | +proxy_headers = { |
| 280 | + "Proxy-Authorization": f"Basic {encoded_credentials}" |
| 281 | +} |
| 282 | + |
| 283 | +config = Configuration( |
| 284 | + server_api_url="https://api.orkes.io/api", |
| 285 | + proxy="http://proxy.company.com:8080", |
| 286 | + proxy_headers=proxy_headers |
| 287 | +) |
| 288 | +``` |
0 commit comments