Python SDK · Feature

IP Geolocation in Python

Turn any IP address into geolocation, network, and threat intelligence with one call. The lookup method on the official ip-api-io client returns the country, city, coordinates, timezone, ISP, and ASN of an IP — plus the suspicious_factors flags used for fraud screening — in a single response.

Trusted by thousands of businesses
Fast JSON API responses
Real-time validation
Simple integration, SDKs & examples
What it does

Geolocation without browser GPS

IP-based geolocation works entirely server-side — no permission prompt, no client SDK, and it works for every visitor and every log line you already have. ip-api.io resolves an IP to a physical location and, uniquely, returns security signals (VPN, proxy, Tor, datacenter, threat) in the same response, so you can localize content and screen for fraud in one round trip.

Prerequisites

  • Python 3.8 or higher
  • The ip-api-io package installed (pip install ip-api-io)
  • A free ip-api.io API key
1

Geolocate one IP with lookup

Pass any IPv4 or IPv6 address, or omit the argument to geolocate the caller's own IP.

import os
from ipapi_io import IpApiClient

client = IpApiClient(api_key=os.environ["IP_API_IO_KEY"])

info = client.lookup("8.8.8.8")

print(info["ip"])                          # "8.8.8.8"
print(info["isp"])                         # "Google LLC"
print(info["location"]["country"])         # "United States"
print(info["location"]["city"])            # "Mountain View"
print(info["location"]["latitude"],
      info["location"]["longitude"])
print(info["location"]["timezone"])        # "America/Los_Angeles"
print(info["suspicious_factors"]["is_datacenter"])  # True

Resolve the IP of the machine making the request by calling lookup() with no argument:

me = client.lookup()
print(me["ip"], me["location"]["country"])
Behind a proxy? Pass the real client IP from the X-Forwarded-For header to lookup(ip) rather than relying on the socket address. See the SDK overview for a Flask example.
2

Geolocate up to 100 IPs with lookup_batch

Enrich logs, sign-up events, or historical data without a round trip per IP. The SDK validates the limit client-side and raises ValueError if the list is empty or longer than 100.

batch = client.lookup_batch(["8.8.8.8", "1.1.1.1", "9.9.9.9"])

print(batch["total_processed"])     # 3
print(batch["successful_lookups"])  # 3
print(batch["failed_lookups"])      # 0

for ip, info in batch["results"].items():
    print(ip, info["location"]["country"], info["suspicious_factors"]["is_vpn"])
Reference

Response reference

lookup() returns a plain dict (typed as IpInfo). Location fields are None for private or unrecognized addresses.

FieldTypeDescription
ipstrThe looked-up address
ispstr | NoneInternet service provider
asnstr | NoneAutonomous system the IP belongs to
locationdictcountry, country_code, city, latitude, longitude, zip, timezone, local_time, local_time_unix, is_daylight_savings
suspicious_factorsdictis_proxy, is_vpn, is_tor_node, is_datacenter, is_spam, is_crawler, is_threat
FAQ

Frequently asked questions

How do I get the location of an IP address in Python?

Install ip-api-io, create a client with your API key, and call client.lookup(ip). The returned dict has a location object with country, city, latitude, longitude and timezone, plus a suspicious_factors object with VPN/proxy/Tor flags.

Can I geolocate the caller's own IP without passing an address?

Yes. Call client.lookup() with no argument and the API resolves the IP from the request. Behind a proxy, pass the real client IP from the X-Forwarded-For header to client.lookup(ip) instead.

How do I look up many IP addresses at once?

Use client.lookup_batch(ips) with up to 100 addresses in one request. It returns a results dict of IP to info plus total_processed, successful_lookups and failed_lookups. It raises ValueError if the list is empty or longer than 100.

Is IP geolocation accurate?

Country-level accuracy is about 99.8% and city-level 85–95% depending on region. Coordinates have a median accuracy radius of roughly 50 km (WGS84). It is ideal for routing, localization, timezone detection and fraud signals — not street-level precision.

Start building with the ip-api.io Python SDK

Install ip-api-io, drop in your free API key, and ship in minutes — one zero-dependency client for geolocation, fraud detection, and email validation.

Need support?

Explore how IP-API.io can enhance your security, provide robust bot protection, and improve IP geolocation accuracy for your applications.

Contact Support

Found a bug in the SDK?

The ip-api-io package is open source. Open an issue or pull request on GitHub and we'll take a look.

Open on GitHub