Socket library has an API to do reverse DNS lookups.
import socket
socket.gethostbyaddr("8.8.8.8")
>>> ('google-public-dns-a.google.com', [], ['8.8.8.8'])
Keep in mind that not all IP addresses will have reverse DNS entries, not all aliases might be present in the answer to this query etc.