Python 3.4+socketterm
socket.AddressFamily
constants
An IntEnum of address families: AF_INET (IPv4), AF_INET6 (IPv6), AF_UNIX and others.
Syntax
socket.AddressFamily.AF_INET # то же, что socket.AF_INET
Since 3.11 print(socket.AF_INET) prints 2, not the name, because str() of an IntEnum became the number; .name gives the name and repr() the full form. Numeric values differ between operating systems (AF_INET6 is 10 on Linux, 30 on macOS, 23 on Windows), so compare against the constant, never a number. AF_UNIX is not available everywhere, older Windows lacks it entirely.
Examples
# Python 3.11+
import socket
print(repr(socket.AF_INET)) # → <AddressFamily.AF_INET: 2>
print(socket.AF_INET) # → 2
print(socket.AF_INET.name) # → AF_INET
print(isinstance(socket.AF_INET6, socket.AddressFamily)) # → True
print(socket.AF_INET6.value) # → ? 10 на Linux, 30 на macOS, 23 на Windows
See also
Open in the full glossarydocs.python.orgReport an inaccuracy