This document is for py-amqp's development version, which can be significantly different from previous releases. Get the stable docs here: 5.3.

# `amqp.transport`

Transport implementation.

class amqp.transport._AbstractTransport(host, connect_timeout=None, read_timeout=None, write_timeout=None, socket_settings=None, raise_on_initial_eintr=True, **kwargs)

  Common superclass for TCP and SSL transports.

  PARAMETERS:

    host: str

    > Broker address in format `HOSTNAME:PORT`.

    connect_timeout: int

    > Timeout of creating new connection.

    read_timeout: int

    > sets `SO_RCVTIMEO` parameter of socket.

    write_timeout: int

    > sets `SO_SNDTIMEO` parameter of socket.

    socket_settings: dict

    > dictionary containing optname and `optval` passed to `setsockopt(2)`.

    raise_on_initial_eintr: bool

    > when True, `socket.timeout` is raised when exception is received during first read. See `_read()` for details.

  close()
  connect()
  connect_timeout
  connection
  having_timeout(timeout)
  host
  port
  raise_on_initial_eintr
  read_frame(unpack=<built-in function unpack>)

    Parse AMQP frame.

    Frame has following format:

        0      1         3         7                   size+7      size+8
        +------+---------+---------+   +-------------+   +-----------+
        | type | channel |  size   |   |   payload   |   | frame-end |
        +------+---------+---------+   +-------------+   +-----------+
         octet    short     long        'size' octets        octet

  read_timeout
  sock
  socket_settings
  write(s)
  write_timeout

class amqp.transport.SSLTransport(host, connect_timeout=None, ssl=None, **kwargs)

  Transport that works over SSL.

  PARAMETERS:

    host: str

    > Broker address in format `HOSTNAME:PORT`.

    connect_timeout: int

    > Timeout of creating new connection.

    ssl: bool|dict

    > parameters of TLS subsystem.

    >   - when `ssl` is not dictionary, defaults of TLS are used

    >   - otherwise:

    >       - if `ssl` dictionary contains `context` key, `_wrap_context` is used for wrapping socket. `context` is a dictionary passed to `_wrap_context` as context parameter. All others items from `ssl` argument are passed as `sslopts`.

    >       - if `ssl` dictionary does not contain `context` key, `_wrap_socket_sni` is used for wrapping socket. All items in `ssl` argument are passed to `_wrap_socket_sni` as parameters.

    kwargs:

    > additional arguments of `_AbstractTransport` class

  _wrap_context(sock, sslopts, check_hostname=None, **ctx_options)

    Wrap socket without SNI headers.

    PARAMETERS:

      sock: socket.socket

      Socket to be wrapped.

      sslopts: dict

      > Parameters of `ssl.SSLContext.wrap_socket`.

      check_hostname

      > Whether to match the peer cert’s hostname. See `ssl.SSLContext.check_hostname` for details.

      ctx_options

      > Parameters of `ssl.create_default_context`.

  _wrap_socket_sni(sock, keyfile=None, certfile=None, server_side=False, cert_reqs=None, ca_certs=None, do_handshake_on_connect=False, suppress_ragged_eofs=True, server_hostname=None, ciphers=None, ssl_version=None)

    Socket wrap with SNI headers.

    stdlib `ssl.SSLContext.wrap_socket` method augmented with support for setting the server_hostname field required for SNI hostname header.

    PARAMETERS:

      sock: socket.socket

      > Socket to be wrapped.

      keyfile: str

      > Path to the private key

      certfile: str

      > Path to the certificate

      server_side: bool

      > Identifies whether server-side or client-side behavior is desired from this socket. See `wrap_socket` for details.

      cert_reqs: ssl.VerifyMode

      > When set to other than `ssl.CERT_NONE`, peers certificate is checked. Possible values are `ssl.CERT_NONE`, `ssl.CERT_OPTIONAL` and `ssl.CERT_REQUIRED`.

      ca_certs: str

      > Path to “certification authority” (CA) certificates used to validate other peers’ certificates when `cert_reqs` is other than `ssl.CERT_NONE`.

      do_handshake_on_connect: bool

      > Specifies whether to do the SSL handshake automatically. See `wrap_socket` for details.

      suppress_ragged_eofs (bool):

      > See `wrap_socket` for details.

      server_hostname: str

      > Specifies the hostname of the service which we are connecting to. See `wrap_socket` for details.

      ciphers: str

      > Available ciphers for sockets created with this context. See `ssl.SSLContext.set_ciphers`

      ssl_version:

      > Protocol of the SSL Context. The value is one of `ssl.PROTOCOL_*` constants.

  sslopts

class amqp.transport.TCPTransport(host, connect_timeout=None, read_timeout=None, write_timeout=None, socket_settings=None, raise_on_initial_eintr=True, **kwargs)

  Transport that deals directly with TCP socket.

  All parameters are `_AbstractTransport` class.

  connect_timeout
  connection
  host
  port
  raise_on_initial_eintr
  read_timeout
  sock
  socket_settings
  write_timeout

class amqp.transport.Transport(host, connect_timeout=None, ssl=False, **kwargs)

  Create transport.

  Given a few parameters from the Connection constructor, select and create a subclass of `_AbstractTransport`.

  PARAMETERS:

  > host: str

  > > Broker address in format `HOSTNAME:PORT`.

  > connect_timeout: int

  > > Timeout of creating new connection.

  > ssl: bool|dict

  > > If set, `SSLTransport` is used and `ssl` parameter is passed to it. Otherwise `TCPTransport` is used.

  > kwargs:

  > > additional arguments of `_AbstractTransport` class