API Reference

aiohappyeyeballs.AddrInfoType

A tuple representing socket address information.

Indexes:

[0] Union[int, socket.AddressFamily]

The address family, e.g. socket.AF_INET

[1] Union[int, socket.SocketKind]

The type of socket, e.g. socket.SOCK_STREAM.

[2] int

The protocol number, e.g. socket.IPPROTO_TCP.

[3] str

The canonical name of the address, e.g. "www.example.com".

[4] Tuple

The socket address tuple, e.g. ("127.0.0.1", 443).

alias of Tuple[int | AddressFamily, int | SocketKind, int, str, Tuple]

aiohappyeyeballs.SocketFactoryType

A callable that creates a socket from an AddrInfoType.

Parameters:

AddrInfoType – Address info for creating the socket containing the address family, socket type, protocol, host address, and additional details.

Return type:

socket.socket

alias of Callable[[Tuple[int | AddressFamily, int | SocketKind, int, str, Tuple]], socket]

aiohappyeyeballs.addr_to_addr_infos(addr: Tuple[str, int, int, int] | Tuple[str, int, int] | Tuple[str, int] | None) List[Tuple[int | AddressFamily, int | SocketKind, int, str, Tuple]] | None

Convert an address tuple to a list of addr_info tuples.

aiohappyeyeballs.pop_addr_infos_interleave(addr_infos: List[Tuple[int | AddressFamily, int | SocketKind, int, str, Tuple]], interleave: int | None = None) None

Pop addr_info from the list of addr_infos by family up to interleave times.

The interleave parameter is used to know how many addr_infos for each family should be popped of the top of the list.

aiohappyeyeballs.remove_addr_infos(addr_infos: List[Tuple[int | AddressFamily, int | SocketKind, int, str, Tuple]], addr: Tuple[str, int] | Tuple[str, int, int, int]) None

Remove an address from the list of addr_infos.

The addr value is typically the return value of sock.getpeername().

async aiohappyeyeballs.start_connection(addr_infos: Sequence[Tuple[int | AddressFamily, int | SocketKind, int, str, Tuple]], *, local_addr_infos: Sequence[Tuple[int | AddressFamily, int | SocketKind, int, str, Tuple]] | None = None, happy_eyeballs_delay: float | None = None, interleave: int | None = None, loop: AbstractEventLoop | None = None, socket_factory: Callable[[Tuple[int | AddressFamily, int | SocketKind, int, str, Tuple]], socket] | None = None) socket

Connect to a TCP server.

Create a socket connection to a specified destination. The destination is specified as a list of AddrInfoType tuples as returned from getaddrinfo().

The arguments are, in order:

  • family: the address family, e.g. socket.AF_INET or

    socket.AF_INET6.

  • type: the socket type, e.g. socket.SOCK_STREAM or

    socket.SOCK_DGRAM.

  • proto: the protocol, e.g. socket.IPPROTO_TCP or

    socket.IPPROTO_UDP.

  • canonname: the canonical name of the address, e.g.

    "www.python.org".

  • sockaddr: the socket address

This method is a coroutine which will try to establish the connection in the background. When successful, the coroutine returns a socket.

The expected use case is to use this method in conjunction with loop.create_connection() to establish a connection to a server:

socket = await start_connection(addr_infos)
transport, protocol = await loop.create_connection(
    MyProtocol, sock=socket, ...)