Bringing Location to the Internet

Python Library

This module is a Python Library to support all IP2Location™ database products. It has been optimized for speed and memory utilization. Developers can use this API to query all IP2Location™ binary databases for applications written in Python.

Download IP2Location Python Library (478.44 kB) Version: 4.0.0

 

Installation
  1. Download IP2Location C library at here.
  2. Decompress C library.
    tar ip2location-c-x.x.x.tar.gz
  3. Download and decompress Python library.
    tar ip2location-python-x.x.x.tar.gz
  4. Get into working directory.
    cd ip2location-python-x.x.x
  5. Edit setup.py to point library_dirs and include_dirs ponting to IP2Location C library folder.
  6. Start compilation.
    python setup.py build && python setup.py install

 

*For MacOS X:
  1. Download IP2Location C library at here.
  2. Decompress C library.
    tar ip2location-c-x.x.x.tar.gz
  3. cd C-IP2Location-<version>/libIP2Location
  4. export CFLAGS=-I/usr/include/malloc
  5. gcc -arch i386 -arch x86_64 -arch ppc -c IP2Location.c iMath/imath.c
  6. gcc -arch i386 -arch x86_64 -arch ppc -dynamiclib -current_version 1.0 -o /usr/local/lib/libIP2Location.dylib IP2Location.o imath.o
  7. Download and decompress Python library.
    tar ip2location-python-x.x.x.tar.gz
  8. cd <path>/ip2location-python-<version>
  9. python setup.py build && python setup.py install

 

Sample Codes
import IP2Location;

IP2LocObj = IP2Location.IP2Location();
IP2LocObj.open("data/IP-COUNTRY-SAMPLE.BIN");
rec = IP2LocObj.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

 

Sample Database (BIN)

Evaluation version of the database file having limited range of IP address information. You can query all IP addresses from 0.0.0.0 to 99.255.255.255 only.