# Connection Parameters

To maintain flexibility in how you specify the connection information required for your applications to properly connect to RabbitMQ, pika implements two classes for encapsulating the information, `ConnectionParameters` and `URLParameters`.

## ConnectionParameters

The classic object for specifying all of the connection parameters required to connect to RabbitMQ, `ConnectionParameters` provides attributes for tweaking every possible connection option.

Example:

    import pika

    # Set the connection parameters to connect to rabbit-server1 on port 5672
    # on the / virtual host using the username "guest" and password "guest"
    credentials = pika.PlainCredentials('guest', 'guest')
    parameters = pika.ConnectionParameters('rabbit-server1',
                                           5672,
                                           '/',
                                           credentials)

class `pika.connection.``ConnectionParameters`(host=<class 'pika.connection.ConnectionParameters._DEFAULT'>, port=<class 'pika.connection.ConnectionParameters._DEFAULT'>, virtual_host=<class 'pika.connection.ConnectionParameters._DEFAULT'>, credentials=<class 'pika.connection.ConnectionParameters._DEFAULT'>, channel_max=<class 'pika.connection.ConnectionParameters._DEFAULT'>, frame_max=<class 'pika.connection.ConnectionParameters._DEFAULT'>, heartbeat=<class 'pika.connection.ConnectionParameters._DEFAULT'>, ssl=<class 'pika.connection.ConnectionParameters._DEFAULT'>, ssl_options=<class 'pika.connection.ConnectionParameters._DEFAULT'>, connection_attempts=<class 'pika.connection.ConnectionParameters._DEFAULT'>, retry_delay=<class 'pika.connection.ConnectionParameters._DEFAULT'>, socket_timeout=<class 'pika.connection.ConnectionParameters._DEFAULT'>, locale=<class 'pika.connection.ConnectionParameters._DEFAULT'>, backpressure_detection=<class 'pika.connection.ConnectionParameters._DEFAULT'>, blocked_connection_timeout=<class 'pika.connection.ConnectionParameters._DEFAULT'>, client_properties=<class 'pika.connection.ConnectionParameters._DEFAULT'>, **kwargs)

  Connection parameters object that is passed into the connection adapter upon construction.

  `backpressure_detection`

    Returns: | boolean indicating whether backpressure detection is enabled. Defaults to DEFAULT_BACKPRESSURE_DETECTION.

  `blocked_connection_timeout`

    Returns: | None or float blocked connection timeout. Defaults to DEFAULT_BLOCKED_CONNECTION_TIMEOUT.

  `channel_max`

    Returns: | max preferred number of channels. Defaults to DEFAULT_CHANNEL_MAX.
    Return type: | int

  `client_properties`

    Returns: | None or dict of client properties used to override the fields in the default client poperties reported to RabbitMQ via Connection.StartOk method. Defaults to DEFAULT_CLIENT_PROPERTIES.

  `connection_attempts`

    Returns: | number of socket connection attempts. Defaults to DEFAULT_CONNECTION_ATTEMPTS.

  `credentials`

    Return type: | one of the classes from pika.credentials.VALID_TYPES. Defaults to DEFAULT_CREDENTIALS.

  `frame_max`

    Returns: | desired maximum AMQP frame size to use. Defaults to DEFAULT_FRAME_MAX.

  `heartbeat`

    Returns: | desired connection heartbeat timeout for negotiation or None to accept broker’s value. 0 turns heartbeat off. Defaults to DEFAULT_HEARTBEAT_TIMEOUT.
    Return type: | integer, float, or None

  `host`

    Returns: | hostname or ip address of broker. Defaults to DEFAULT_HOST.
    Return type: | str

  `locale`

    Returns: | locale value to pass to broker; e.g., ‘en_US’. Defaults to DEFAULT_LOCALE.
    Return type: | str

  `port`

    Returns: | port number of broker’s listening socket. Defaults to DEFAULT_PORT.
    Return type: | int

  `retry_delay`

    Returns: | interval between socket connection attempts; see also connection_attempts. Defaults to DEFAULT_RETRY_DELAY.
    Return type: | float

  `socket_timeout`

    Returns: | socket timeout value. Defaults to DEFAULT_SOCKET_TIMEOUT.
    Return type: | float

  `ssl`

    Returns: | boolean indicating whether to connect via SSL. Defaults to DEFAULT_SSL.

  `ssl_options`

    Returns: | None or a dict of options to pass to ssl.wrap_socket. Defaults to DEFAULT_SSL_OPTIONS.

  `virtual_host`

    Returns: | rabbitmq virtual host name. Defaults to DEFAULT_VIRTUAL_HOST.

## URLParameters

The `URLParameters` class allows you to pass in an AMQP URL when creating the object and supports the host, port, virtual host, ssl, username and password in the base URL and other options are passed in via query parameters.

Example:

    import pika

    # Set the connection parameters to connect to rabbit-server1 on port 5672
    # on the / virtual host using the username "guest" and password "guest"
    parameters = pika.URLParameters('amqp://guest:guest@rabbit-server1:5672/%2F')

class `pika.connection.``URLParameters`(url)

  Connect to RabbitMQ via an AMQP URL in the format:

      amqp://username:password@host:port/<virtual_host>[?query-string]

  Ensure that the virtual host is URI encoded when specified. For example if you are using the default “/” virtual host, the value should be %2f.

  See Parameters for default values.

  Valid query string values are:

  > - backpressure_detection:
  >     DEPRECATED in favor of Connection.Blocked and Connection.Unblocked. See Connection.add_on_connection_blocked_callback.
  > - channel_max:
  >     Override the default maximum channel count value
  > - client_properties:
  >     dict of client properties used to override the fields in the default client properties reported to RabbitMQ via Connection.StartOk method
  > - connection_attempts:
  >     Specify how many times pika should try and reconnect before it gives up
  > - frame_max:
  >     Override the default maximum frame size for communication
  > - heartbeat:
  >     Specify the number of seconds between heartbeat frames to ensure that the link between RabbitMQ and your application is up
  > - locale:
  >     Override the default en_US locale value
  > - ssl:
  >     Toggle SSL, possible values are t, f
  > - ssl_options:
  >     Arguments passed to `ssl.wrap_socket()`
  > - retry_delay:
  >     The number of seconds to sleep before attempting to connect on connection failure.
  > - socket_timeout:
  >     Override low level socket timeout value
  > - blocked_connection_timeout:
  >     Set the timeout, in seconds, that the connection may remain blocked (triggered by Connection.Blocked from broker); if the timeout expires before connection becomes unblocked, the connection will be torn down, triggering the connection’s on_close_callback

  Parameters: | url (str) – The AMQP URL to connect to

  `backpressure_detection`

    Returns: | boolean indicating whether backpressure detection is enabled. Defaults to DEFAULT_BACKPRESSURE_DETECTION.

  `blocked_connection_timeout`

    Returns: | None or float blocked connection timeout. Defaults to DEFAULT_BLOCKED_CONNECTION_TIMEOUT.

  `channel_max`

    Returns: | max preferred number of channels. Defaults to DEFAULT_CHANNEL_MAX.
    Return type: | int

  `client_properties`

    Returns: | None or dict of client properties used to override the fields in the default client poperties reported to RabbitMQ via Connection.StartOk method. Defaults to DEFAULT_CLIENT_PROPERTIES.

  `connection_attempts`

    Returns: | number of socket connection attempts. Defaults to DEFAULT_CONNECTION_ATTEMPTS.

  `credentials`

    Return type: | one of the classes from pika.credentials.VALID_TYPES. Defaults to DEFAULT_CREDENTIALS.

  `frame_max`

    Returns: | desired maximum AMQP frame size to use. Defaults to DEFAULT_FRAME_MAX.

  `heartbeat`

    Returns: | desired connection heartbeat timeout for negotiation or None to accept broker’s value. 0 turns heartbeat off. Defaults to DEFAULT_HEARTBEAT_TIMEOUT.
    Return type: | integer, float, or None

  `host`

    Returns: | hostname or ip address of broker. Defaults to DEFAULT_HOST.
    Return type: | str

  `locale`

    Returns: | locale value to pass to broker; e.g., ‘en_US’. Defaults to DEFAULT_LOCALE.
    Return type: | str

  `port`

    Returns: | port number of broker’s listening socket. Defaults to DEFAULT_PORT.
    Return type: | int

  `retry_delay`

    Returns: | interval between socket connection attempts; see also connection_attempts. Defaults to DEFAULT_RETRY_DELAY.
    Return type: | float

  `socket_timeout`

    Returns: | socket timeout value. Defaults to DEFAULT_SOCKET_TIMEOUT.
    Return type: | float

  `ssl`

    Returns: | boolean indicating whether to connect via SSL. Defaults to DEFAULT_SSL.

  `ssl_options`

    Returns: | None or a dict of options to pass to ssl.wrap_socket. Defaults to DEFAULT_SSL_OPTIONS.

  `virtual_host`

    Returns: | rabbitmq virtual host name. Defaults to DEFAULT_VIRTUAL_HOST.