1.9. geoip
¶
This module uses GeoLite2 data created by MaxMind, available from http://www.maxmind.com.
1.9.1. Data¶
1.9.2. Functions¶
-
download_geolite2_city_db
(dest, license=None, date=None)[source]¶ Download the GeoLite2 database and save it to disk.
Changed in version 1.16.0: Added the license and date parameters.
Parameters: - dest (str) – The file path to save the database to.
- license (str) – The MaxMind license key to use to download the database.
- date (
datetime.date
) – The date for which to download the database.
-
init_database
(database_file)[source]¶ Create and initialize the GeoLite2 database engine. This must be done before classes and functions in this module attempt to look up results. If the specified database file does not exist, a new copy will be downloaded.
Parameters: database_file (str) – The GeoLite2 database file to use. Returns: The initialized GeoLite2 database object. Return type: geoip2.database.Reader
-
lookup
(ip, lang='en')[source]¶ Lookup the geo location information for the specified IP from the configured GeoLite2 City database.
Parameters: Returns: The geo location information as a dict. The keys are the values of
DB_RESULT_FIELDS
.Return type:
1.9.3. Classes¶
-
class
GeoLocation
(ip, lang='en', result=None)[source]¶ The geographic location information for a given IP address. If result is not specified,
lookup()
will be used to obtain the information.-
__geo_interface__
[source]¶ A simple implementation of the Python __geo_interface__ specification. This allows this object to be used with modules which also support this interface such as
geojson
.Returns: A dictionary describing a this location as a GeoJSON Point. Return type: dict
-
ip_address
[source]¶ The
IPv4Address
which this geographic location data describes.
-