Skip to content

IPInfoManager

The IPInfoManager class handles IP geolocation using IPInfo's database with a singleton pattern.


Methods

def initialize(self): """Initialize and download the database if needed."""

def get_country(self, ip: str) -> str | None: """Get country code for an IP address."""

def close(self): """Close the database connection."""

Usage Example

from djangoapi_guard import IPInfoManager

ipinfo_db = IPInfoManager(token="your_token")
ipinfo_db.initialize()

country = ipinfo_db.get_country("8.8.8.8")
print(f"Country: {country}")  # Output: "US"