Guide

How to Optimize Checkout with an IP Geolocation API

Pre-fill currency and country, and add a payment-risk signal — from one lookup — to cut checkout friction and fraud.

You can cut checkout friction and add a fraud signal from a single IP lookup: pre-select the local currency, pre-fill the country field, and flag payments coming from datacentre networks for review. The response carries currency, country and connection type — everything you need, with the user always able to override.

Python

The examples here are Python, standard library only — but the same logic maps directly onto our official SDKs for TypeScript, Go, Ruby, Java and 7 more. Field paths and the worked outputs below are all verified against the live API.

1Get a key and call the API securely

Create a free account here — 2,000 lookups/day, no card. Send the key as an Authorization: Bearer header from an environment variable, keeping it out of URLs and logs:

Python
import os, urllib.request, json

API_KEY=***  # export it; never hardcode

def lookup(ip):
    req = urllib.request.Request(
        f"https://api.ipwho.org/ip/{ip}",
        headers={"Authorization": f"Bearer {API_KEY}", "User-Agent": "MyApp/1.0"},
    )
    with urllib.request.urlopen(req, timeout=10) as resp:
        return json.loads(resp.read())["data"]

2Pre-fill currency and country, flag datacentre payments:

Read currency.code / symbol to pre-select the store currency, geoLocation.countryCode to pre-fill the billing country, and treat a Corporate connection type as a payment-risk signal worth a closer look:

Python
def checkout_context(data):
    geo  = data.get("geoLocation") or {}
    cur  = data.get("currency") or {}
    conn = data.get("connection") or {}
    return {
        "currency": cur.get("code"),           # pre-select store currency
        "symbol":   cur.get("symbol"),
        "prefill_country": geo.get("countryCode"),  # pre-fill, not lock
        "payment_risk": "review" if conn.get("connection_type") == "Corporate" else "normal",
    }

print(checkout_context(lookup("91.0.0.1")))

3Wire it into checkout — the full script:

Everything together. Remember these are defaults: show the detected currency and country, but always let the shopper change them — a traveller or expat may want a different one. Tested against the live API (2026-10-26):

Python
#!/usr/bin/env python3
"""Checkout context from an IP (IPWho IP geolocation API):
local currency + country prefill + a datacentre payment-risk flag."""
import os, sys, urllib.request, json

API_KEY=*** lookup(ip):
    req = urllib.request.Request(
        f"https://api.ipwho.org/ip/{ip}",
        headers={"Authorization": f"Bearer {API_KEY}", "User-Agent": "IPWho-Checkout/1.0"},
    )
    with urllib.request.urlopen(req, timeout=10) as resp:
        return json.loads(resp.read())["data"]

def checkout_context(data):
    geo  = data.get("geoLocation") or {}
    cur  = data.get("currency") or {}
    conn = data.get("connection") or {}
    return {
        "currency": cur.get("code") or "USD",
        "symbol":   cur.get("symbol") or "$",
        "prefill_country": geo.get("countryCode"),
        "payment_risk": "review" if conn.get("connection_type") == "Corporate" else "normal",
    }

if __name__ == "__main__":
    ip = sys.argv[1] if len(sys.argv) > 1 else "91.0.0.1"
    print(f"{ip}: {checkout_context(lookup(ip))}")
Output
$ python3 checkout.py 91.0.0.1       # Germany
91.0.0.1: {'currency': 'EUR', 'symbol': '€', 'prefill_country': 'DE', 'payment_risk': 'normal'}

$ python3 checkout.py 76.102.11.203  # USA
76.102.11.203: {'currency': 'USD', 'symbol': '$', 'prefill_country': 'US', 'payment_risk': 'normal'}

$ python3 checkout.py 52.95.110.1    # AWS datacentre -> flagged
52.95.110.1: {'currency': 'USD', 'symbol': '$', 'prefill_country': 'US', 'payment_risk': 'review'}

Start with a free API key

Free tier: 2,000 lookups/day, no card. Paid plans from $2.50/month. Full field reference here, or see the checkout-optimization use case here.