# Delete Channel (/sdks/python/how-to/management/delete-channel)



## Overview [#overview]

Deleting a channel is how you decommission a topic, queue, or RPC endpoint you no longer need — tearing down test fixtures between CI runs, retiring a deprecated integration, or cleaning up the throwaway channels a demo or load test created. It's a permanent, immediate operation: the channel's routing entry is removed from the broker and any messages still sitting in it are discarded, so it's not something you want triggered by a typo in a shared environment.

Under the hood, each client exposes its own typed delete methods — `delete_events_channel_async`, `delete_events_store_channel_async`, `delete_queues_channel_async`, `delete_commands_channel_async`, and `delete_queries_channel_async` — scoped to `PubSubClient`, `QueuesClient`, or `CQClient`. Because channels are namespaced by type, an events channel and a queues channel can share the same name without colliding, and deleting one never touches the other.

**Gotchas:** deleting a channel that doesn't exist raises an error rather than succeeding silently, so idempotent cleanup code needs to wrap each call in `try/except` and ignore the not-found case — as the example does. There's no "soft delete" or recovery window — once it's gone, any messages still queued are gone with it. And a client can only delete channels of the type it owns; asking a `QueuesClient` to delete an events channel isn't an option, you need the matching client type.

## Prerequisites [#prerequisites]

* KubeMQ server running on `localhost:50000`
* Python SDK installed (`pip install kubemq`)

## Code [#code]

```python title="delete_channel.py"
"""Example: Delete channel — delete channels for events, events store, queues, and CQ."""

from __future__ import annotations

import asyncio

from kubemq import CQClient
from kubemq import PubSubClient
from kubemq import QueuesClient


async def main() -> None:
    # Delete events channels
    async with PubSubClient(
        address="localhost:50000",
        client_id="python-management-delete-channel-client",
    ) as client:
        try:
            await client.delete_events_channel_async("python-management.create-events")
            print("Events channel deleted: python-management.create-events")
        except Exception as e:
            print(f"Error deleting events channel: {e}")

        try:
            await client.delete_events_store_channel_async("python-management.create-events-store")
            print("Events store channel deleted: python-management.create-events-store")
        except Exception as e:
            print(f"Error deleting events store channel: {e}")

    # Delete queues channel
    async with QueuesClient(
        address="localhost:50000",
        client_id="python-management-delete-channel-client",
    ) as client:
        try:
            await client.delete_queues_channel_async("python-management.create-queues")
            print("Queues channel deleted: python-management.create-queues")
        except Exception as e:
            print(f"Error deleting queues channel: {e}")

    # Delete CQ channels
    async with CQClient(
        address="localhost:50000",
        client_id="python-management-delete-channel-client",
    ) as client:
        try:
            await client.delete_commands_channel_async("python-management.create-commands")
            print("Commands channel deleted: python-management.create-commands")
        except Exception as e:
            print(f"Error deleting commands channel: {e}")

        try:
            await client.delete_queries_channel_async("python-management.create-queries")
            print("Queries channel deleted: python-management.create-queries")
        except Exception as e:
            print(f"Error deleting queries channel: {e}")


if __name__ == "__main__":
    asyncio.run(main())

```

## How It Works [#how-it-works]

`delete_*_channel_async` removes the channel and all associated metadata from the broker. Each client type (`PubSubClient`, `QueuesClient`, `CQClient`) can only delete channels it owns. Deleting a non-existent channel raises an error from the broker, so the example wraps each call in `try/except` to handle missing channels gracefully. The channel names used here match those created in the Create Channel example.

## Related [#related]

* [Python SDK Reference](/sdks/python/reference)
* [Create Channel](/sdks/python/how-to/management/create-channel)
* [List Channels](/sdks/python/how-to/management/list-channels)
