{"id":8198,"library":"geoip2fast","title":"GeoIP2Fast","description":"GeoIP2Fast is a high-performance Python library for GeoIP2 country, city, and ASN lookups, supporting both IPv4 and IPv6. It boasts lookup speeds of less than 0.00003 seconds and utilizes its own data files, updated twice a week with MaxMind GeoLite2 CSV data. The library is pure Python, has no external dependencies, and is currently at version 1.2.2.","status":"active","version":"1.2.2","language":"en","source_language":"en","source_url":"https://github.com/rabuchaim/geoip2fast","tags":["GeoIP","IP Geolocation","IPv4","IPv6","ASN","Country","City","MaxMind"],"install":[{"cmd":"pip install geoip2fast","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"GeoIP2Fast","correct":"from geoip2fast import GeoIP2Fast"}],"quickstart":{"code":"import os\nfrom geoip2fast import GeoIP2Fast\n\n# Ensure data file is present, or download it. For this example, we assume it's in the current directory.\n# In a real application, you might use GeoIP2Fast.update_all() or provide a path to an existing file.\n# For demonstration, we'll try to use a common data file that might be downloaded separately.\n# If not found, a FileNotFoundError will be raised, indicating the data file needs to be obtained.\n\ndata_file = os.environ.get('GEOIP2FAST_DATA_FILE', 'geoip2fast-asn-ipv6.dat.gz')\n\ntry:\n    # Initialize GeoIP2Fast with a specific data file (e.g., with ASN and IPv6 support)\n    # The library looks in the current directory and then in the library's package directory.\n    geoip = GeoIP2Fast(geoip2fast_data_file=data_file, verbose=False)\n\n    # Lookup an IPv4 address\n    ip_v4 = \"8.8.8.8\"\n    result_v4 = geoip.lookup(ip_v4)\n    print(f\"IPv4 Lookup for {ip_v4}: {result_v4.country_name}, ASN: {result_v4.asn_name}\")\n\n    # Lookup an IPv6 address\n    ip_v6 = \"2001:4860:4860::8888\"\n    result_v6 = geoip.lookup(ip_v6)\n    print(f\"IPv6 Lookup for {ip_v6}: {result_v6.country_name}, ASN: {result_v6.asn_name}\")\n\n    # Example of a private IP address\n    private_ip = \"192.168.1.1\"\n    result_private = geoip.lookup(private_ip)\n    print(f\"Private IP {private_ip}: is_private={result_private.is_private}\")\n\nexcept FileNotFoundError:\n    print(f\"Error: GeoIP2Fast data file '{data_file}' not found.\")\n    print(\"Please download the necessary .dat.gz file from the GitHub releases (e.g., https://github.com/rabuchaim/geoip2fast/releases/tag/LATEST) and place it in the application directory or specify its path.\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")","lang":"python","description":"Initializes the GeoIP2Fast library with a specified data file and performs IP lookups for both IPv4 and IPv6 addresses. It demonstrates how to retrieve country name and ASN details, and handles private IP addresses. It includes error handling for missing data files."},"warnings":[{"fix":"Download the appropriate '.dat.gz' file from the GitHub releases page for your installed library version. For v1.2.x, look for the 'LATEST' tag; for v1.1.x, look for the 'LEGACY' tag.","message":"Data files for GeoIP2Fast v1.2.x are not compatible with v1.1.x (and older versions), and vice-versa. Ensure you use the correct data file version corresponding to your installed library version.","severity":"breaking","affected_versions":">=1.2.0 (incompatible with <1.2.0)"},{"fix":"Initialize `GeoIP2Fast` with the `geoip2fast_data_file` argument pointing to your desired `.dat.gz` file, or ensure the default `geoip2fast.dat.gz` is present in your application or library path. Data files are available on the GitHub releases page.","message":"GeoIP2Fast requires a data file (`.dat.gz`) for lookups. While the library can download data files using `GeoIP2Fast.update_all()`, you might need to manually download a specific variant (e.g., for City or ASN data) and place it in your application's directory or specify its path.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Handle the 'not found in database' result in your application logic if a lookup does not yield a specific entry. The result object will still be returned, but fields like `country_name` might be empty or indicate 'not found'.","message":"When an IP address is not found in the database, GeoIP2Fast explicitly returns 'not found in database' rather than falling back to a less precise geographical location. This is by design to ensure accuracy.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Remove any custom overrides or expectations based on `sys.tracebacklimit = 0` when upgrading to v1.2.2 or newer.","message":"The line `sys.tracebacklimit = 0` was removed in v1.2.2 as it caused issues in environments like Django. If you relied on this behavior, be aware it's no longer present.","severity":"deprecated","affected_versions":">=1.2.2"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Ensure the `geoip2fast.dat.gz` (or your chosen data file, e.g., `geoip2fast-asn-ipv6.dat.gz`) is present in the same directory as your script or in the `site-packages/geoip2fast` directory. Alternatively, specify the full path to the data file when initializing `GeoIP2Fast(geoip2fast_data_file='/path/to/your/file.dat.gz')`. Download the latest files from the official GitHub releases.","cause":"The required GeoIP2Fast data file (or the specified custom file) could not be found by the library.","error":"FileNotFoundError: [Errno 2] No such file or directory: 'geoip2fast.dat.gz'"},{"fix":"This is an intended behavior of GeoIP2Fast; it does not infer location for IPs not explicitly in its database. Verify the IP is valid and consider if a different, more comprehensive (and possibly larger) data file (e.g., a city/ASN database) might contain the entry if available.","cause":"The IP address queried exists, but its network block is not present in the loaded GeoIP2Fast database.","error":"network not found in database"},{"fix":"Check the format of the IP address string being passed to the `lookup()` method. Ensure it adheres to standard IPv4 (e.g., '192.168.1.1') or IPv6 (e.g., '2001:0db8::') notation.","cause":"The input string provided for lookup is not a syntactically valid IPv4 or IPv6 address.","error":"invalid ip address"}]}