I don't see how such functionality could be implemented purely with the socket module. The socket module is for working directly with sockets: opening/closing, sending/receiving, etc. It's simply a thin wrapper over the standard BSD socket interface.
On the other hand, getting metadata about existing sockets already allocated on the system requires knowledge of the other processes running on a system. This has little to do with actually manipulating a socket, and much more to do with monitoring other processes and/or their file descriptors.
For example, it seems that both ss and netstat are actually implemented (at least on Linux) by reading and parsing the /proc pseudo-filesystem. (See here and here, for examples.) The kernel manages the processes and their opened sockets, and exposes (some of) the information about them to other processes via procfs. This provides a simple and safe way of exporting some of the information about processes to userspace, obviating the need for lots of system calls or reading kernel data structures directly.
Note that it pretty much has to work this way. Strong process isolation necessitates that information about another process's open files, including sockets, has to come through the kernel in some way. That could be either via procfs on Linux, or some kernel-provided API (e.g. libproc on macOS). Anything else would be a massive security hole.
As an alternative to the socket module, you could try the psutil package or something similar. The psutil.net_connections() function seems appropriate.