DEV Community

Ing. Pablo Cueto
Ing. Pablo Cueto

Posted on

I built and deployed an IP Geolocation API from scratch in one day — here's the full stack

No third-party black boxes. No vendor lock-in. Just clean Python code, two free data sources, and a live API on RapidAPI.

The stack

  • FastAPI — async endpoints, automatic Swagger docs
  • IPLocate.io — primary geo source (VPN/proxy/Tor detection on free tier)
  • ipgeolocation.io — automatic fallback
  • In-memory TTL cache — LRU cache, 1h TTL, 10k entries
  • Render — auto-deploy from GitHub on every push
  • RapidAPI — marketplace distribution, billing, rate limiting

What it does

  • GET /ip/{ip} — full geolocation for any IPv4 or IPv6
  • GET /ip/me — auto-detect caller's IP
  • POST /ip/bulk — up to 50 IPs in one request
  • Security flags on every response: VPN, Tor, proxy, datacenter

The architecture decision that matters

Two geo sources with automatic failover. If IPLocate goes down, ipgeolocation.io takes over silently. The client never sees a 502. Cache handles repeated lookups without touching either upstream API.

The response

{
  "ip": "8.8.8.8",
  "location": {
    "country": "United States",
    "city": "Mountain View",
    "latitude": 37.38605,
    "longitude": -122.08385
  },
  "security": {
    "is_vpn": false,
    "is_tor": false,
    "is_datacenter": true
  },
  "source": "iplocate"
}
Enter fullscreen mode Exit fullscreen mode

Try it live

https://rapidapi.com/PabsCueto/api/ip-geolocation38

Free tier available. Bulk endpoint included from the first paid plan. The entire project — models, services, routers, tests, render.yaml — is a clean FastAPI structure you can fork and adapt for any data enrichment API.

python #fastapi #api #webdev #programming #backend #devops #opensource #buildinpublic #pythondeveloper #apidesign #render #rapidapi #geolocation #cybersecurity

Top comments (0)