This is an IP geolocation library that enables the user to find the country, region, city, latitude and longitude, ZIP code, time zone, ISP, domain name, area code, weather info, mobile info, elevation, usage type, address type and IAB category from an IP address. It supports both IPv4 and IPv6 lookup.
pip install IP2LocationVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to load an IP2Location BIN database file and query geolocation information for an IP address. You must download a database file separately and provide its path.
Download the appropriate BIN database from IP2Location (e.g., https://lite.ip2location.com/ip2location-lite for free LITE data) and provide its path during `IP2Location.IP2Location()` initialization.
Ensure you are importing `IP2Location` if you intend to use local BIN files. If you need the web API, install and use `ip2location-io` as per its documentation.
Monitor memory usage when using `SHARED_MEMORY`. If memory is a concern, use the default `FILE_IO` mode, or consider using a smaller database. For large databases, ensure ample RAM is available.
For applications with multiple threads accessing the database concurrently, consider initializing a new `IP2Location` object for each thread or process to prevent potential resource conflicts or race conditions. If a single instance is shared, implement explicit synchronization (e.g., `threading.Lock`).
Ensure the library is installed using pip: `pip install IP2Location` and that the import statement is `import IP2Location`.
Verify that the BIN database file is present at the provided path. If it's in the same directory as your script, ensure you reference it correctly, e.g., `db = IP2Location.IP2Location('IP2LOCATION-LITE-DB1.BIN')` or provide an absolute path.Pass the path to your IP2Location BIN database file when creating the `IP2Location` object: `db = IP2Location.IP2Location('path/to/your/IP2LOCATION-LITE-DB1.BIN')`.Ensure that the IP2Location BIN database you downloaded supports the fields you are trying to query. LITE databases might have fewer fields than commercial ones. Check the database documentation for available fields. For example, if you want ISP information, you might need a DB5 or higher.
No dependency data recorded yet.