rabbitpy Connection objects are used to connect to RabbitMQ. They provide a thread-safe connection to RabbitMQ that is used to authenticate and send all channel based RPC commands over. Connections use AMQP URI syntax for specifying the all of the connection information, including any connection negotiation options, such as the heartbeat interval. For more information on the various query parameters that can be specified, see the official documentation.

A Connection is a normal python object that you use:

conn = rabbitpy.Connection('amqp://guest:guest@localhost:5672/%2F')

or it can be used as a Python context manager (See PEP 0343):

with rabbitpy.Connection() as conn:
    # Foo

When it is used as a context manager with the with statement, when your code exits the block, the connection will automatically close.

If RabbitMQ remotely closes your connection via the AMQP Connection.Close RPC request, rabbitpy will raise the appropriate exception referenced in the request.

If heartbeats are enabled (default: 5 minutes) and RabbitMQ does not send a heartbeat request in >= 2 heartbeat intervals, a ConnectionResetException will be raised.

API Documentation

class rabbitpy.Connection(url=None)[source]

The Connection object is responsible for negotiating a connection and managing its state. When creating a new instance of the Connection object, if no URL is passed in, it uses the default connection parameters of localhost port 5672, virtual host / with the guest/guest username/password combination. Represented as a AMQP URL the connection information is:


To use a different connection, pass in a AMQP URL that follows the standard format:


The following example connects to the test virtual host on a RabbitMQ server running at port 5672 as the user “www” and the password rabbitmq:



You should be aware that most connection exceptions may be raised during the use of all functionality in the library.

Parameters:url (str) – The AMQP connection URL

Return the connection arguments.

Return type:dict

Indicates if the connection is blocked from publishing by RabbitMQ.

This flag indicates communication from RabbitMQ that the connection is blocked using the Connection.Blocked RPC notification from RabbitMQ that was added in RabbitMQ 3.2.

Return type:bool

Return the RabbitMQ Server capabilities from the connection negotiation process.

Return type:dict

Create a new channel

If blocking_read is True, the cross-thread Queue.get use will use blocking operations that lower resource utilization and increase throughput. However, due to how Python’s blocking Queue.get is implemented, KeyboardInterrupt is not raised when CTRL-C is pressed.

Parameters:blocking_read (bool) – Enable for higher throughput

Close the connection, including all open channels.


Return the RabbitMQ Server properties from the connection negotiation process.

Return type:dict