IP Geolocation in Python
pygeon is a Python geolocation toolkit. It can construct a geolocation database from publicly available data held on the RIRs’ FTP servers, and then allows lookups both from the command line and via its API.
See the documentation for more details.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.