IP Geolocation with MaxMind and ipapi-style Services¶
Verified status as of March 28, 2026. Runtime note: FastFN auto-installs function-local dependencies from
requirements.txt/package.json; host runtimes are required infastfn dev --native, whilefastfn devdepends on a running Docker daemon. This article shows a practicalip -> countrysetup with two FastFN examples:
/ip-intel/maxmind: local lookup with MaxMind-style MMDB (GeoLite2-Country.mmdb)./ip-intel/remote: remote lookup using an ipapi-style HTTP service.
Run the examples¶
1) MaxMind local lookup¶
Quick deterministic test (no DB file required):
Real MMDB lookup:
# Install Python dependency once in the function folder:
# echo "maxminddb>=2.6.2" > examples/functions/ip-intel/requirements.txt
# Then restart fastfn dev so runtime installs it.
MAXMIND_DB_PATH=/absolute/path/to/GeoLite2-Country.mmdb \
curl -s "http://127.0.0.1:8080/ip-intel/maxmind?ip=8.8.8.8"
Response shape:
{
"ok": true,
"provider": "maxmind",
"ip": "8.8.8.8",
"country_code": "US",
"country_name": "United States"
}
2) ipapi-style remote lookup¶
Deterministic test mode:
Real remote lookup:
The handler expects /{ip}/json/ style endpoints and normalizes common fields:
country_code, country_name, city, region.
Tests included¶
Unit tests:
Integration checks (includes both geolocation routes):
Key takeaway¶
This article gives you two working shapes for the same feature: local database lookup when you want stable latency and control, and remote HTTP lookup when you want the shortest setup. Both return the same normalized fields, so clients do not need to care which provider answered the request.
What to keep in mind¶
- Use
mock=1first so tests stay deterministic while you wire the real provider. - Refresh the MaxMind database on a schedule if you rely on local lookups.
- Keep your public response shape stable even if the upstream provider exposes extra fields.
When to choose the other path¶
- Pick local MMDB lookup when privacy, predictable latency, or offline behavior matters.
- Pick a remote provider when you do not want to manage database downloads and refreshes.
- Avoid doing geolocation inline on every hot path if the result can be cached earlier in the request flow.