Skip to content

Python SDK

PyPI GitHub

The IPWho Python SDK wraps the IP geolocation API in idiomatic Python — typed dataclass responses, built-in error classes, and a single pip install. One call returns the full payload: geolocation, timezone, currency, connection (ASN/ISP), security flags, and more.

Terminal window
pip install ipwho-ip-geolocation-api

Python 3.8+, requests. Import path: from ipwho import IPWhoClient.

import os
from ipwho import IPWhoClient
client = IPWhoClient(api_key=os.environ["IPWHO_API_KEY"])
resp = client.lookup("8.8.8.8") # GET /ip/{ip}
me = client.me() # GET /me
bulk = client.bulk(["8.8.8.8", "1.1.1.1"]) # GET /bulk/{a,b,c}
print(resp.data.geo_location.country) # United States
print(resp.data.connection.asn_number) # 15169
from ipwho import IPWhoClient, InvalidIPError, RateLimitError, APIResponseError
try:
resp = client.lookup("8.8.8.8")
except InvalidIPError:
# malformed IP address (404)
except RateLimitError:
# plan limit reached (429)
except APIResponseError:
# unexpected response
v1v2
from src import IPWhofrom ipwho import IPWhoClient
get_location(ip) / get_ip(ip)lookup(ip) then resp.data.geo_location
get_me()me()
(missing)bulk(ips)
  • lookup(ip) — GET /ip/{ip}
  • me() — GET /me
  • bulk(ips) — GET /bulk/{a,b,c}; rows on data.response_array