Python SDK
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.
- Source: lavrox/SDK-IPWho-IP-Geolocation-Python
- PyPI:
ipwho-ip-geolocation-apiv2.0.0 - API key: ipwho.org/free-plan
Installation
Section titled “Installation”pip install ipwho-ip-geolocation-apiPython 3.8+, requests. Import path: from ipwho import IPWhoClient.
Quick start
Section titled “Quick start”import osfrom 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 /mebulk = client.bulk(["8.8.8.8", "1.1.1.1"]) # GET /bulk/{a,b,c}
print(resp.data.geo_location.country) # United Statesprint(resp.data.connection.asn_number) # 15169Error handling
Section titled “Error handling”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 responseMigrating from v1
Section titled “Migrating from v1”| v1 | v2 |
|---|---|
from src import IPWho | from ipwho import IPWhoClient |
get_location(ip) / get_ip(ip) | lookup(ip) then resp.data.geo_location |
get_me() | me() |
| (missing) | bulk(ips) |
Methods
Section titled “Methods”lookup(ip)—GET /ip/{ip}me()—GET /mebulk(ips)—GET /bulk/{a,b,c}; rows ondata.response_array