# Select Connection Adapter

Asynchronous adapter without third-party dependencies.

## Interacting with Pika from another thread

> `pika.SelectConnection`’s I/O loop provides `add_callback_threadsafe()` to allow interacting with Pika from another thread.

## Class Reference

A connection adapter that tries to use the best polling method for the platform pika is running on.

class pika.adapters.select_connection.SelectConnection(parameters: connection.Parameters | None = None, on_open_callback: Callable[[connection.Connection], None] | None = None, on_open_error_callback: Callable[[connection.Connection, BaseException], None] | None = None, on_close_callback: Callable[[connection.Connection, BaseException], None] | None = None, custom_ioloop: nbio_interface.AbstractIOServices | IOLoop | None = None, internal_connection_workflow: bool = True)

  An asynchronous connection adapter that attempts to use the fastest event loop adapter for the given platform.

  add_on_close_callback(callback: Callable[[Connection, Exception], Any]) → None

    Add a callback notification when the connection has closed. The callback will be passed the connection and an exception instance. The exception will either be an instance of exceptions.ConnectionClosed if a fully-open connection was closed by user or broker or exception of another type that describes the cause of connection closure/failure.

    Parameters:

      callback (callable) – Callback to call on close, having the signature: callback(pika.connection.Connection, exception)

  add_on_connection_blocked_callback(callback: Callable[[Connection, Method[Blocked]], Any]) → None

    RabbitMQ AMQP extension - Add a callback to be notified when the connection gets blocked (Connection.Blocked received from RabbitMQ) due to the broker running low on resources (memory or disk). In this state RabbitMQ suspends processing incoming data until the connection is unblocked, so it’s a good idea for publishers receiving this notification to suspend publishing until the connection becomes unblocked.

    See also Connection.add_on_connection_unblocked_callback()

    See also ConnectionParameters.blocked_connection_timeout.

    Parameters:

      callback (callable) – Callback to call on Connection.Blocked, having the signature callback(connection, pika.frame.Method), where the method frame’s method member is of type pika.spec.Connection.Blocked

  add_on_connection_unblocked_callback(callback: Callable[[Connection, Method[Unblocked]], Any]) → None

    RabbitMQ AMQP extension - Add a callback to be notified when the connection gets unblocked (Connection.Unblocked frame is received from RabbitMQ) letting publishers know it’s ok to start publishing again.

    Parameters:

      callback (callable) – Callback to call on Connection.Unblocked, having the signature callback(connection, pika.frame.Method), where the method frame’s method member is of type pika.spec.Connection.Unblocked

  add_on_open_callback(callback: Callable[[Connection], Any]) → None

    Add a callback notification when the connection has opened. The callback will be passed the connection instance as its only arg.

    Parameters:

      callback (callable) – Callback to call when open

  add_on_open_error_callback(callback: Callable[[Connection, BaseException | None], Any], remove_default: bool = True) → None

    Add a callback notification when the connection can not be opened.

    The callback method should accept the connection instance that could not connect, and either a string or an exception as its second arg.

    Parameters:

      - callback (callable) – Callback to call when can’t connect, having the signature _(Connection, Exception)

      - remove_default (bool) – Remove default exception raising callback

  property basic_nack: bool

    Specifies if the server supports basic.nack on the active connection.

    Return type:

      bool

  channel(channel_number: int | None = None, on_open_callback: Callable[[Channel], Any] | None = None) → Channel

    Create a new channel with the next available channel number or pass in a channel number to use. Must be non-zero if you would like to specify but it is recommended that you let Pika manage the channel numbers.

    Parameters:

      - channel_number (int) – The channel number to use, defaults to the next available.

      - on_open_callback (callable) – The callback when the channel is opened. The callback will be invoked with the Channel instance as its only argument.

    Return type:

      pika.channel.Channel

  close(reply_code: int = 200, reply_text: str = 'Normal shutdown') → None

    Disconnect from RabbitMQ. If there are any open channels, it will attempt to close them prior to fully disconnecting. Channels which have active consumers will attempt to send a Basic.Cancel to RabbitMQ to cleanly stop the delivery of messages prior to closing the channel.

    Parameters:

      - reply_code (int) – The code number for the close

      - reply_text (str) – The text reason for the close

    Raises:

      pika.exceptions.ConnectionWrongStateError – if connection is closed or closing.

  property consumer_cancel_notify: bool

    Specifies if the server supports consumer cancel notification on the active connection.

    Return type:

      bool

  classmethod create_connection(connection_configs: Sequence[connection.Parameters], on_done: Callable[[connection.Connection | connection_workflow.AMQPConnectorException], None], custom_ioloop: Any | None = None, workflow: connection_workflow.AbstractAMQPConnectionWorkflow | None = None) → connection_workflow.AbstractAMQPConnectionWorkflow

    Implement :py:classmethod::pika.adapters.BaseConnection.create_connection().

  property exchange_exchange_bindings: bool

    Specifies if the active connection supports exchange to exchange bindings.

    Return type:

      bool

  property ioloop: Any
    Returns:

      the native I/O loop instance underlying async services selected by user or the default selected by the specialized connection adapter (e.g., Twisted reactor, asyncio.SelectorEventLoop, select_connection.IOLoop, etc.)

    Return type:

      object

  property is_closed: bool

    Returns a boolean reporting the current connection state.

  property is_closing: bool

    Returns True if connection is in the process of closing due to client-initiated close request, but closing is not yet complete.

  property is_open: bool

    Returns a boolean reporting the current connection state.

  property publisher_confirms: bool

    Specifies if the active connection can use publisher confirmations.

    Return type:

      bool

  update_secret(new_secret: str, reason: str, callback: Callable[[Method[UpdateSecretOk]], Any] | None = None) → None

    RabbitMQ AMQP extension - This method updates the secret used to authenticate this connection. It is used when secrets have an expiration date and need to be renewed, like OAuth 2 tokens. Pass a callback to be notified of the response from the server.

    Parameters:

      - new_secret (string) – The new secret

      - reason (string) – The reason for the secret update

      - callback (callable) – Callback to call on Connection.UpdateSecretOk, having the signature callback(pika.frame.Method), where the method frame’s method member is of type pika.spec.Connection.UpdateSecretOk

    Raises:

      pika.exceptions.ConnectionWrongStateError – if connection is not open.