Skip to main content

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.2.2

Released August 24, 2020.

  • Added X_FORWARDED_FOR headers support.

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.

Source Distribution

Flask-Simple-GeoIP-0.2.2.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

Flask_Simple_GeoIP-0.2.2-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file Flask-Simple-GeoIP-0.2.2.tar.gz.

File metadata

  • Download URL: Flask-Simple-GeoIP-0.2.2.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7

File hashes

Hashes for Flask-Simple-GeoIP-0.2.2.tar.gz
Algorithm Hash digest
SHA256 5ca093f28ea24f5ef02e9d9cd3d59d66d844bcad55d8b03e71edd5114e101e1d
MD5 12815476ddab38049f1009d2545419d2
BLAKE2b-256 29230d529423b988dc6ea62af0f4d45d195b3401d5de921476aa9ed308b5ec41

See more details on using hashes here.

File details

Details for the file Flask_Simple_GeoIP-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: Flask_Simple_GeoIP-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/49.6.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.7.7

File hashes

Hashes for Flask_Simple_GeoIP-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2d0a5c8758e47e3d964ffe54197395589fed32dac1e82e3f84cdd5e5458f2d29
MD5 f3a6a3397dffb092e8f683f64126123b
BLAKE2b-256 f387854dd3eb5f7bf18d870ec67d791652b57a593fd2375eac3cf033ccfe8675

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page