Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

The simplest GeoIP lookup library for Flask.

Project description

The simplest GeoIP lookup library for Flask.

https://raw.githubusercontent.com/whois-api-llc/flask-simple-geoip/master/images/geoip.png flask-simple-geoip Release flask-simple-geoip Build

Meta

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 flask-simple-geoip using pypi, simply run:

$ pip install flask-simple-geoip

In the root of your project directory.

Usage

Once you have flask-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.

Here’s a simple Flask app that makes use of the geolocation lookups:

from flask import Flask, jsonify
from flask_simple_geoip import SimpleGeoIP


app = Flask(__name__)

# Initialize the extension
simple_geoip = SimpleGeoIP(app)


@app.route('/')
def test():
    # Retrieve geoip data for the given requester
    geoip_data = simple_geoip.get_geoip_data()

    return jsonify(data=geoip_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.

In the event a geoip lookup still can’t return successfully, the data returned will be None. This library will never throw an exception. This decision was made strategically: not having geoip data should never be the cause of a failed request. =)

Changelog

All library changes in descending order.

Version 0.1.1

Released June 18, 2018.

  • Fixing readme so it shows properly on PyPI :(

Version 0.1.0

Released June 18, 2018.

  • First release!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for Flask-Simple-GeoIP, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size Flask_Simple_GeoIP-0.1.1-py2.py3-none-any.whl (3.5 kB) File type Wheel Python version py2.py3 Upload date Hashes View hashes
Filename, size Flask-Simple-GeoIP-0.1.1.tar.gz (3.6 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page