Skip to main content

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; you will obtain an API key that will be needed to use the library.

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__)

# The API key is obtained from the GEOIPIFY_API_KEY environment variable.
# Alternatively it can be set as follows:
# app.config.update(GEOIPIFY_API_KEY='YOUR_API_KEY')

# 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.4

Released October 27, 2020.

  • Described in the readme how to supply the API key.

Version 0.2.3

Released August 26, 2020.

  • Fixed pypy support.

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!

Metadata

Release files for Flask-Simple-GeoIP 0.2.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for Flask-Simple-GeoIP 0.2.4
File Size Uploaded
Flask-Simple-GeoIP-0.2.4.tar.gz 4.3 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for Flask-Simple-GeoIP 0.2.4
File Interpreter ABI Platform
Flask_Simple_GeoIP-0.2.4-py3-none-any.whl Python 3 none any Details

Total release size: 8.3 kB

Release files / Flask-Simple-GeoIP-0.2.4.tar.gz

Download URL Flask-Simple-GeoIP-0.2.4.tar.gz
Size 4.3 kB
Tags Source
SHA-256 checksum
How to use checksums
9655b4be1249b90b422d61d388032a4ff4f691aac632d2581ee88f44a6512ff1
BLAKE2b-256 checksum
How to use checksums
634a20ca3efa0e3fe00eab5b4491041d7f598c1969008f9449f17c2fe81d0ecf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.5

Release files / Flask_Simple_GeoIP-0.2.4-py3-none-any.whl

Download URL Flask_Simple_GeoIP-0.2.4-py3-none-any.whl
Size 4.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dfbfa618d13a271cd7ae91359c253debf58a0a3e772a8400ca0a1c4aa29282f4
BLAKE2b-256 checksum
How to use checksums
0dbbff9f39a9be21cfae80dabb29bb7fda73371a1e6506abd6ed49cc84302fa3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.6.1 requests/2.24.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.51.0 CPython/3.8.5

Release history Release notifications | RSS feed

This release

0.2.4 This release

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page