pydase/docs/user-guide/advanced/SOCKS-Proxy.md
2025-05-20 20:43:16 +02:00

1.3 KiB

Connecting Through a SOCKS5 Proxy

If your target service is only reachable via an SSH gateway or resides behind a firewall, you can route your [pydase.Client][pydase.Client] connection through a local SOCKS5 proxy. This is particularly useful in network environments where direct access to the service is not possible.

Setting Up a SOCKS5 Proxy

You can create a local SOCKS5 proxy using SSH's -D option:

ssh -D 2222 user@gateway.example.com

This command sets up a SOCKS5 proxy on localhost:2222, securely forwarding traffic over the SSH connection.

Using the Proxy in Your Python Client

Once the proxy is running, configure the [pydase.Client][pydase.Client] to route traffic through it using the proxy_url parameter:

import pydase

client = pydase.Client(
    url="ws://target-service:8001",
    proxy_url="socks5://localhost:2222"
).proxy
  • You can also use this setup with wss:// URLs for encrypted WebSocket connections.

Installing Required Dependencies

To use this feature, you must install the optional socks dependency group, which includes aiohttp_socks:

  • poetry
    poetry add "pydase[socks]"
    
  • pip
    pip install "pydase[socks]"