A Channel is created on an active connection using the method. Channels can act as normal Python objects:

conn = rabbitpy.Connection()
chan =

or as a Python context manager (See PEP 0343):

with rabbitpy.Connection() as conn:
    with as chan:

When they are used as a context manager with the with statement, when your code exits the block, the channel will automatically close, issuing a clean shutdown with RabbitMQ via the Channel.Close RPC request.

You should be aware that if you perform actions on a channel with exchanges, queues, messages or transactions that RabbitMQ does not like, it will close the channel by sending an AMQP Channel.Close RPC request to your application. Upon receipt of such a request, rabbitpy will raise the appropriate exception referenced in the request.

API Documentation

class rabbitpy.Channel(channel_id, server_capabilities, events, exception_queue, read_queue, write_queue, maximum_frame_size, write_trigger, connection, blocking_read=False)[source]

The Channel object is the communications object used by Exchanges, Messages, Queues, and Transactions. It is created by invoking the method. It can act as a context manager, allowing for quick shorthand use:

   # Do something

To create a new channel, invoke

To improve performance, pass blocking_read to True. Note that doing so prevents KeyboardInterrupt/CTRL-C from exiting the Python interpreter.

  • channel_id (int) – The channel # to use for this instance
  • server_capabilities (dict) – Features the server supports
  • events (rabbitpy.Events) – Event management object
  • exception_queue (queue.Queue) – Exception queue
  • read_queue (queue.Queue) – Queue to read pending frames from
  • write_queue (queue.Queue) – Queue to write pending AMQP objs to
  • maximum_frame_size (int) – The max frame size for msg bodies
  • write_trigger (socket) – Write to this socket to break IO waiting
  • blocking_read (bool) – Use blocking Queue.get to improve performance





Close the channel, cancelling any active consumers, purging the read queue, while looking to see if a Basic.Nack should be sent, sending it if so.


Turn on Publisher Confirms. If confirms are turned on, the Message.publish command will return a bool indicating if a message has been successfully published.


Return the channel id

Return type:int

Return the AMQP maximum frame size

Return type:int

Open the channel, invoked directly upon creation by the Connection

prefetch_count(value, all_channels=False)[source]

Set a prefetch count for the channel (or all channels on the same connection).

  • value (int) – The prefetch count to set
  • all_channels (bool) – Set the prefetch count on all channels on the same connection
prefetch_size(value, all_channels=False)[source]

Set a prefetch size in bytes for the channel (or all channels on the same connection).

  • value (int) – The prefetch size to set
  • all_channels (bool) – Set the prefetch size on all channels on the same connection

Returns True if publisher confirms are enabled.

Return type:bool

Recover all unacknowledged messages that are associated with this channel.

Parameters:requeue (bool) – Requeue the message