***

title: disconnect
slug: /reference/python/relay/client/disconnect
description: Close the WebSocket connection cleanly.
max-toc-depth: 3
---------------------

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

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

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

Cleanly close the WebSocket connection to SignalWire RELAY. This cancels the
internal receive loop, ping monitor, all pending JSON-RPC requests, any queued
requests waiting for reconnection, and any in-progress dial operations. The
client is fully reset and can be reconnected with
[`connect()`][connect].

<Note>
  When using the async context manager (`async with client:`), `disconnect()` is
  called automatically on exit. When using
  [`run()`][run], disconnection happens
  automatically on `Ctrl+C` or when the event loop is stopped.
</Note>

## **Parameters**

None.

## **Returns**

`None`

## **Example**

```python {22}
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()

    # Do work ...
    message = await client.send_message(
        to_number="+15559876543",
        from_number="+15551234567",
        body="Hello!",
    )
    await message.wait()

    await client.disconnect()

asyncio.run(main())
```