A simple Python library that queries multiple geolocation services until one succeeds.
Project description
whereismyip
An IP address geolocation module for Python 3 that only uses the standard library (and the whatismyip package) and free, no-registration geolocation services.
The package exposes two main convenience functions: whereismyip(ip) and whereismyip_dict(ip)
The IP address argument can be an IPv4 or IPv6 address. If this argument is not given, the whatismyip package is used to determine your public IP address (also from free, no-registration services.) All geolocation services are free, don't require registration, and use HTTPS.
Example
>>> import whereismyip
>>> whereismyip.whereismyip()
'Bellevue, Washington, US'
>>> whereismyip.whereismyip_dict()
{'city': 'Bellevue', 'latitude': None, 'ip': '23.234.81.85', 'country': 'US', 'longitude': None, 'region': 'Washington'}
>>> whereismyip.whereismyip_dict() # The geolocate service used is randomly selected, so replies may be different.
{'city': 'Portland', 'latitude': 45.5230622, 'ip': '23.234.81.85', 'country': 'United States', 'longitude': -122.6764816, 'region': 'Oregon'}
>>> whereismyip.whereismyip("8.8.8.8")
'Mountain View, California, United States'
>>> whereismyip.whereismyip_dict('8.8.8.8')
{'city': 'Mountain View', 'latitude': 37.3860517, 'ip': '8.8.8.8', 'country': 'United States', 'longitude': -122.0838511, 'region': 'California'}
Reference
def whereismyip(
ip_address: str = "",
timeout: int = 2,
attempts: int = 2,
user_agent: str = "python-urllib",
providers=_GEO_FUNCS,
) -> str:
def whereismyip_dict(
ip_address: str = "",
timeout: int = 2,
attempts: int = 2,
user_agent: str = "python-urllib",
providers=_GEO_FUNCS,
) -> dict:
The four geolocation services are ipwhois.io, ipapi.co, IPinfo.io, and FindIP.net.
def geolocate_ipwhois_io(
ip_address: str = "",
timeout: int = 2,
user_agent: str = "python-urllib",
) -> dict:
def geolocate_ipapi_co(
ip_address: str = "",
timeout: int = 2,
user_agent: str = "python-urllib",
) -> dict:
def geolocate_ipinfo_lite(
ip_address: str = "",
timeout: int = 2,
user_agent: str = "python-urllib",
) -> dict:
def geolocate_findip_net(
ip_address: str = "",
timeout: int = 2,
user_agent: str = "python-urllib",
) -> dict:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file whereismyip-0.1.0.tar.gz.
File metadata
- Download URL: whereismyip-0.1.0.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a4cc17cc44a41940f115f97b26fb16e2ffc9eef3eded2c34638908d4d5a6595f
|
|
| MD5 |
dbabc462cadb5b3ce648ef10d1b2b05a
|
|
| BLAKE2b-256 |
d91e666b76c8737bf517db8b7bcac23c49dd9f421bc1d4ce7f8935da341403ba
|
File details
Details for the file whereismyip-0.1.0-py3-none-any.whl.
File metadata
- Download URL: whereismyip-0.1.0-py3-none-any.whl
- Upload date:
- Size: 3.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
12ee972905c24afd67bd06bda39a60d4915f836b3f29d3af477587d6464eeaa5
|
|
| MD5 |
3167438de15bef69e60e2c6dfeee9f92
|
|
| BLAKE2b-256 |
d6c23422551baf56e3707221817ea3810d3b17553bb5624950d5429a4fc5bb18
|