The simplest possible way to get IP geolocation information.
Project description
The simplest possible way to get IP geolocation information in Python.
Meta
Author: Randall Degges
Email: r@rdegges.com
Twitter: https://twitter.com/rdegges
Site: http://www.rdegges.com
Status: production ready
Prerequisites
To use this library, you’ll need to create a free GeoIPify account: https://geoipify.whoisxmlapi.com/
If you haven’t done this yet, please do so now.
Installation
To install simple-geoip using pypi, simply run:
$ pip install simple-geoip
In the root of your project directory.
Usage
Once you have simple-geoip installed, you can use it to easily find the physical location of a given IP address.
This library gives you access to all sorts of geographical location data that you can use in your application in any number of ways.
from simple_geoip import GeoIP
geoip = GeoIP("your-api-key");
try:
data = geoip.lookup("8.8.8.8")
except ConnectionError:
# If you get here, it means you were unable to reach the geoipify
# service, most likely because of a network error on your end.
except ServiceError:
# If you get here, it means geoipify is having issues, so the request
# couldn't be completed :(
except:
# Something else happened (non-geoipify) related. Maybe you hit CTRL-C
# while the program was running, the kernel is killing your process, or
# something else all together.
print(data)
Here’s the sort of data you might get back when performing a geoip lookup request:
{
"ip": "8.8.8.8",
"location": {
"country": "US",
"region": "California",
"city": "Mountain View",
"lat": 37.40599,
"lng": -122.078514,
"postalCode": "94043",
"timezone": "-08:00"
}
}
By default, this library handles retrying failed HTTP requests for you. For instance: if the GeoIPify API service is currently down or having issues, your request will be retried up to three consecutive times before failing.
Changelog
All library changes in descending order.
Version 0.1.0
Released April 26, 2018.
First release!
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file simple-geoip-0.1.0.tar.gz
.
File metadata
- Download URL: simple-geoip-0.1.0.tar.gz
- Upload date:
- Size: 5.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | af94afc7f0329a31ab00c86e4e1c72fa38a7438285964b846bdd1b01d18d7467 |
|
MD5 | 4ff46844a0d1e668af70b33fdf57810d |
|
BLAKE2b-256 | 7ce860855c0a74f7f880bb4e727f56543d560ddc108f1cf3c79c594a06c185de |
File details
Details for the file simple_geoip-0.1.0-py2.py3-none-any.whl
.
File metadata
- Download URL: simple_geoip-0.1.0-py2.py3-none-any.whl
- Upload date:
- Size: 5.5 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a6507bd14cfbc8bf9f771fea21a535dd6402e9e25cf12f82e53c4e654417ea9a |
|
MD5 | be9eb1416f80ac188e04695f1d14fe89 |
|
BLAKE2b-256 | 8bda7952f8d4cf57add80d6dea0ae2c2870fa6a9fea2089c5c7ff3d1febd8567 |