Sat 23 May 2026

Python Package - whereismyip

Posted by Al Sweigart in misc   

In August 2025, I created a Python package whereismyip to do simple geolocation based on IP address using free, no-registration online services. This blog post covers the package after a recent update. The source code is available in a git repo. and you can download it with pip or other tools from PyPI. If you are interested in this package, I also have a whatismyip Python package that finds your public IP address. You can also run python -m whereismyip to geolocate yourself (this requires whatismyip) or a specific IP address such as python -m whereismyip 8.8.8.8.

The whereismyip name does not use snakecase because it's named after the whatismyip.com website, an early IP address finding service. For consistency, the other functions are named similiarly.

Here is some example usage:

>>> import whereismyip

>>> whereismyip.whereismyip()
'Bellevue, Washington, United States'

>>> whereismyip.whereismyip_dict()
{'ip': '23.234.81.85', 'city': 'Bellevue', 'region': 'Washington', 'country': 'United States', 'country_code': 'US', 'latitude': 47.6101, 'longitude': -122.2015}

>>> whereismyip.whereismyip_dict()  # The geolocate service used is randomly selected, so values may vary slightly.
{'ip': '23.234.81.85', 'city': 'Bellevue', 'region': 'Washington', 'country': 'United States', 'country_code': 'US', 'latitude': 47.5446, 'longitude': -122.1559}

>>> whereismyip.whereismyip("8.8.8.8")
'Mountain View, California, United States'

>>> whereismyip.whereismyip_dict('8.8.8.8')
{'ip': '8.8.8.8', 'city': 'Mountain View', 'region': 'California', 'country': 'United States', 'country_code': 'US', 'latitude': 37.3860517, 'longitude': -122.0838511}

The four geolocation services are ipwhois.io, ipapi.co, IPinfo.io, and FindIP.net.

The whereismyip module does not have any dependencies outside the Python standard library. It does not require Requests to be installed. However, if you want to automatically geolocate your own IP address without manually passing it in, you'll need the whatismyip package installed.


Check out other books by Al Sweigart, free online or available for purchase:

...and other books as well! Or register for the online video course. You can also donate to or support the author directly.