IPy provides methods for what you want:
>>> from IPy import IP
>>> ip = IP('127.0.0.1')
>>> ip.reverseName()
'1.0.0.127.in-addr.arpa.'
Works for both IPv4 and IPv6, although the original IPy has a few bugs for IPv6. I created a fork with some extensions and fixes at https://github.com/steffann/python-ipy which you can use as long as the fixes haven't been merged back into the original code.
Update:
You can of course also use the getnameinfo function in built-in socket
module:
>>> import socket
>>> socket.getnameinfo(('2001:4860:4860::8888', 0), 0)
('google-public-dns-a.google.com', '0')
>>> socket.getnameinfo(('127.0.0.1', 0), 0)
('localhost', '0')
You need to provide a host+port tuple, but you can provide 0
for the port, and you'll get the hostname back.