fastrag.serve.geolocalization#
Optional GeoIP country resolution for the serving app.
Grouped by feature: resolver holds CountryResolver (the
lookup itself) and dependencies the FastAPI dependency that hands
the app-owned instance to a route or another dependency.
- class fastrag.serve.geolocalization.CountryResolver(database_path)[source]#
Bases:
objectResolves an IP to an ISO-3166 alpha-2 country code, or
None.Built once per app (see
app.py) fromServeConfig.geoip_database_pathand closed by the app’s lifespan on shutdown. Every failure mode — no path configured, thegeoip2extra not installed, the database file missing or unreadable, the address not present in it, or a private/loopback address that was never going to be — degrades silently toNonerather than failing the request. Only the “a path was given but couldn’t be opened” case is worth an operator’s attention, and it is logged at most once per resolver, not once per request.- Parameters:
database_path (Path | str | None)
- fastrag.serve.geolocalization.get_country_resolver(request)[source]#
Return the
CountryResolverbuilt once bycreate_app.A dependency rather than a direct
app.stateread, so tests can swap it viaapp.dependency_overrides[get_country_resolver].- Parameters:
request (Request)
- Return type:
Modules
FastAPI dependency exposing the app's |
|
IP → country resolution against an operator-supplied GeoLite2 database. |