Skip to main content

Python API for IP2Location database. It can be used to identify visitor's geographical location, i.e. country, region, city, latitude, longitude, ZIP code, time zone, connection speed, ISP, domain name, IDD country code, area code, weather station code and name, mobile carrier, elevation and usage type information.

Project description

IP2Location Python Library

This IP2Location Python library enables user to find the country, region or state, city, latitude and longitude, ZIP code, time zone, Internet Service Provider (ISP) or company name, domain name, net speed, area code, weather station code, weather station name, mobile country code (MCC), mobile network code (MNC) and carrier brand, elevation, and usage type by IP address or hostname originates from. The library reads the geo location information from IP2Location BIN data file. It has been optimized for speed and memory utilization. Developers can use this API to easily query the information for all IP2Location binary (BIN) databases by a given IP address. It supported IPv4 and IPv6 address.

This package can be used in many types of projects such as:

  • select the geographically closest mirror
  • analyze your web server logs to determine the countries of your visitors
  • credit card fraud detection
  • software export controls
  • display native language and currency
  • prevent password sharing and abuse of service
  • geotargeting in advertisement

For more details, please visit: https://www.ip2location.com/developers/python

Installation

To install this module type the following:

pip install IP2Location

Usage

	import os
	import IP2Location

	database = IP2Location.IP2Location(os.path.join("data", "IPV6-COUNTRY.BIN"))

	rec = database.get_all("19.5.10.1")

	print(rec.country_short)
	print(rec.country_long)
	print(rec.region)
	print(rec.city)
	print(rec.isp)	
	print(rec.latitude)
	print(rec.longitude)			
	print(rec.domain)
	print(rec.zipcode)
	print(rec.timezone)
	print(rec.netspeed)
	print(rec.idd_code)
	print(rec.area_code)
	print(rec.weather_code)
	print(rec.weather_name)
	print(rec.mcc)
	print(rec.mnc)
	print(rec.mobile_brand)
	print(rec.elevation)
	print(rec.usage_type)
	print("\nYou may download the DB24 sample BIN at https://www.ip2location.com/downloads/sample6.bin.db24.zip for full data display.")

Sample BIN Databases

IPv4 BIN vs IPv6 BIN

  • Use the IPv4 BIN file if you just need to query IPv4 addresses.
  • Use the IPv6 BIN file if you need to query BOTH IPv4 and IPv6 addresses.

Support

Email: support@ip2location.com.
URL: https://www.ip2location.com

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

IP2Location-8.0.2-py3-none-any.whl (2.4 kB view hashes)

Uploaded Python 3

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