Skip to main content

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 convenience functions, whereismyip(ip) and whereismyip_dict(ip), plus a per-provider function for each supported geolocation service if you want to query one directly.

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, 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}

Successful lookups are cached in-process for 2 seconds, so tight loops or repeated calls don't hammer the providers. Pass cache_ttl=0 to bypass, or call whereismyip.clear_cache() to drop the cache.

Command line

After installing, the whereismyip command is available on your PATH. It can also be run as a module:

$ whereismyip
Bellevue, Washington, United States

$ whereismyip 8.8.8.8
Mountain View, California, United States

$ python -m whereismyip 8.8.8.8
Mountain View, California, United States

Exit code is 0 on success, 1 on lookup failure, 2 on usage errors.

Reference

def whereismyip(
    ip_address: str = "",
    timeout: float = 2.0,
    attempts: int = 2,
    user_agent: str = _DEFAULT_USER_AGENT,
    providers=_GEO_FUNCS,
    cache_ttl: float = 2.0,
) -> str:

def whereismyip_dict(
    ip_address: str = "",
    timeout: float = 2.0,
    attempts: int = 2,
    user_agent: str = _DEFAULT_USER_AGENT,
    providers=_GEO_FUNCS,
    cache_ttl: float = 2.0,
) -> dict:

def clear_cache() -> None:

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

def geolocate_ipwhois_io(
    ip_address: str = "",
    timeout: float = 2.0,
    user_agent: str = _DEFAULT_USER_AGENT,
) -> dict:

def geolocate_ipapi_co(
    ip_address: str = "",
    timeout: float = 2.0,
    user_agent: str = _DEFAULT_USER_AGENT,
) -> dict:

def geolocate_ipinfo_lite(
    ip_address: str = "",
    timeout: float = 2.0,
    user_agent: str = _DEFAULT_USER_AGENT,
) -> dict:

def geolocate_findip_net(
    ip_address: str = "",
    timeout: float = 2.0,
    user_agent: str = _DEFAULT_USER_AGENT,
) -> dict:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

whereismyip-2026.5.23.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

whereismyip-2026.5.23-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file whereismyip-2026.5.23.tar.gz.

File metadata

  • Download URL: whereismyip-2026.5.23.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.13

File hashes

Hashes for whereismyip-2026.5.23.tar.gz
Algorithm Hash digest
SHA256 42269d0f68b2627d3c4b5294fa7d8ee1e94d88928e5ba51eab3744110bad4827
MD5 26156c13b4cf0fedf2179b683c49d5a4
BLAKE2b-256 59047e427b95fdc4056707f9b3f0f562c44047defbb300a3a36ddb61f094c07e

See more details on using hashes here.

File details

Details for the file whereismyip-2026.5.23-py3-none-any.whl.

File metadata

File hashes

Hashes for whereismyip-2026.5.23-py3-none-any.whl
Algorithm Hash digest
SHA256 d64d57692d9bf87c6e671da78c1aa6f18c004ab8d443337b1676393ea152f653
MD5 057a0261da3247fe113ad24c57782bbc
BLAKE2b-256 3c6863d1eb1c526c1d61703c71f6ef549b7bfbeca76a93e12e15510da728a2f0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page