# Client (/sdks/python/reference/client)



The Python SDK ships pattern-specific async clients. `AsyncPubSubClient` handles Events and Events Store, `AsyncQueuesClient` handles Queues, and `AsyncCQClient` handles Commands and Queries. All accept the same constructor options and work as async context managers.

## Package [#package]

```bash
pip install kubemq
```

Requires Python 3.9+.

## Client classes [#client-classes]

| Client              | Import                                 | Notes                 |
| ------------------- | -------------------------------------- | --------------------- |
| `AsyncPubSubClient` | `from kubemq import AsyncPubSubClient` | Events + Events Store |
| `AsyncQueuesClient` | `from kubemq import AsyncQueuesClient` | Queues                |
| `AsyncCQClient`     | `from kubemq import AsyncCQClient`     | Commands + Queries    |

### Constructor (illustrative) [#constructor-illustrative]

```python
AsyncPubSubClient(
    address: str = "localhost:50000",
    client_id: str | None = None,
    auth_token: str | None = None,
    ...
)
```

**Parameters:**

| Name              | Type    | Required | Description                   |
| ----------------- | ------- | -------- | ----------------------------- |
| `address`         | `str`   | Yes      | Broker endpoint (`host:port`) |
| `client_id`       | `str`   | No       | Auto-generated when omitted   |
| `auth_token`      | `str`   | No       | Bearer token                  |
| TLS / cert kwargs | various | No       | Mutual TLS configuration      |

**Returns:** Client instance (connect via `async with` or `await client.connect()`).

**Throws:** `KubeMQError` subclasses — connection, validation, or auth failures.

> **Note:** Pass `AsyncCancellationToken` objects into long-running subscriptions to stop workers cooperatively.

## Context managers [#context-managers]

```python
async with AsyncPubSubClient(address="localhost:50000") as client:
    ...
```

## Quick Usage [#quick-usage]

```python title="app.py"
import asyncio
from kubemq import AsyncPubSubClient

async def main():
    async with AsyncPubSubClient(address="localhost:50000", client_id="py-demo") as client:
        await client.ping()

asyncio.run(main())
```

## See Also [#see-also]

* [Connection Examples](/sdks/python/how-to/connection/)
* Concepts
* [Python SDK Getting Started](/sdks/python)
