Skip to main content

Geolocation for Flask

Project description

Flask-Geo

Geolocation for Flask using Maxmind.

Installation

pip install flask-geo

Usage

Initialize the extension:

from flask import Flask
from flask_geo import Geolocation

app = Flask(__name__)
geo = Geolocation(app)

Download a maxmind db:

flask download-geo-db --license-key=XXX

Get the country or city of the visitor:

from flask_geo import geolocate_country, geolocate_city

@app.route("/")
def index():
    country_iso_code = geolocate_country()
    # or
    city_name, country_iso_code = geolocate_city()

[!IMPORTANT] Geolocation results are cached in the session. To clear the cache use clear_geo_cache()

[!TIP] When app.debug is true, you can override which ip address to use for geolocation using the __remoteaddr query parameter: http://localhost:5000?__remoteaddr=1.1.1.1

Configuration

Config key Extension argument Description Default
FLASK_GEO_MAXMIND_DB maxmind_db Filename towards the maxmind db GeoLite2-City.mmdb
FLASK_GEO_USE_CITY_DB is_city_db Whether it is the city db or the country db True
FLASK_GEO_SILENT silent Do not raise any errors whether the db is missing or geolocation fails True

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_geo-0.1.0.tar.gz (3.5 kB view details)

Uploaded Source

Built Distribution

flask_geo-0.1.0-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file flask_geo-0.1.0.tar.gz.

File metadata

  • Download URL: flask_geo-0.1.0.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/6.8.0-40-generic

File hashes

Hashes for flask_geo-0.1.0.tar.gz
Algorithm Hash digest
SHA256 006573c8fbcc4866f288fff862e88a11f486ee38476d26a9b693ccfe8a6063c3
MD5 ef89af4556c97ca90cffd6791f2dccff
BLAKE2b-256 53d94932fb0aa8fa6e644353f06802199eb9532f21049a2dc8083c7c81f44193

See more details on using hashes here.

File details

Details for the file flask_geo-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: flask_geo-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.10.12 Linux/6.8.0-40-generic

File hashes

Hashes for flask_geo-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ad7231fea6d7fd6c78a4919c5f544d183ef0970942595ed5f5fd652d2e65e843
MD5 ef31dfdc70e8d3c5715dc9742ef8e053
BLAKE2b-256 19cbf6b07eee9f3f2400e8c8f1e5ce9766b9e65ccfe1b03fcc718a95e2acf524

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