API Reference¶
- aiohappyeyeballs.AddrInfoType¶
Built-in immutable sequence.
If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable’s items.
If the argument is a tuple, the return value is the same object.
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]
intThe protocol number, e.g.
socket.IPPROTO_TCP.[3]
strThe canonical name of the address, e.g.
"www.example.com".[4]
TupleThe 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_INETorsocket.AF_INET6.
type: the socket type, e.g.socket.SOCK_STREAMorsocket.SOCK_DGRAM.
proto: the protocol, e.g.socket.IPPROTO_TCPorsocket.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, ...)