***

title: connect
slug: /reference/python/relay/client/connect
description: Establish the WebSocket connection and authenticate.
max-toc-depth: 3
---------------------

For a complete index of all SignalWire documentation pages, fetch https://signalwire.com/docs/llms.txt

[run]: /docs/server-sdks/reference/python/relay/client/run

[ref-relayclient]: /docs/server-sdks/reference/python/relay/client

Establish a WebSocket connection to SignalWire RELAY and authenticate. This method
connects to `wss://<host>`, sends a `signalwire.connect` authentication request,
subscribes to the configured contexts, and starts the internal receive loop.

<Note>
  For most use cases, prefer [`run()`][run]
  which calls `connect()` internally and adds automatic reconnection. Use `connect()`
  directly only when you need manual control over the event loop or are using the
  async context manager.
</Note>

<Warning>
  By default, only one [`RelayClient`][ref-relayclient] connection is allowed per process. Calling
  `connect()` on a second instance without disconnecting the first raises
  `RuntimeError`. Set the `RELAY_MAX_CONNECTIONS` environment variable to allow
  multiple concurrent connections.
</Warning>

## **Parameters**

None.

## **Returns**

`None`

## **Examples**

### Manual connect/disconnect

```python {12}
import asyncio
from signalwire.relay import RelayClient

client = RelayClient(
    project="your-project-id",
    token="your-api-token",
    host="your-space.signalwire.com",
    contexts=["default"],
)

async def main():
    await client.connect()
    # Connected and authenticated -- do work here
    call = await client.dial(
        devices=[[{"type": "phone", "params": {"to_number": "+15559876543", "from_number": "+15551234567"}}]]
    )
    await call.hangup()
    await client.disconnect()

asyncio.run(main())
```

### Async context manager

```python {12}
import asyncio
from signalwire.relay import RelayClient

client = RelayClient(
    project="your-project-id",
    token="your-api-token",
    host="your-space.signalwire.com",
    contexts=["default"],
)

async def main():
    async with client:
        call = await client.dial(
            devices=[[{"type": "phone", "params": {"to_number": "+15559876543", "from_number": "+15551234567"}}]]
        )
        await call.hangup()

asyncio.run(main())
```