Getting started with the IPinfo-DB Python Library. Download and Query our databases from Python

The IPinfo-DB Python library takes care of download and querying our databases.

The library currently supports our IP to Country + ASN database in the MMDB format. If you would like us to add our other databases, let us know.

:link: Github Repo - IPinfo/Python-db

:link: Python Package Index PyPI - IPinfo DB


This package works with Python 3.5 or greater. However, we only officially support non-EOL Python versions.

pip install ipinfo-db

Quick Start

# Make sure to install the library
# pip install ipinfo-db
import ipinfo_db

# Sign up for a free account:
# Get your access token from here:
access_token = 'YOUR_TOKEN'

# Intialize client handler
client = ipinfo_db.Client(access_token)

# Input IP address
ip_address = ''

# Getting IP data
details = client.getDetails(ip_address)

The details variable contains the following data as a dictionary

  "as_domain": "",
  "as_name": "Oracle Corporation",
  "asn": "AS31898",
  "continent": "SA",
  "continent_name": "South America",
  "country": "BR",
  "country_name": "Brazil"

IP details methods

Methods Description Example
getDetails(ip_address) Returns all the country and ASN level IP information available for the input IP address in a dictionary format. {‘as_domain’: ‘’, ‘as_name’: ‘Oracle Corporation’, ‘asn’: ‘AS31898’, ‘continent’: ‘SA’, ‘continent_name’: ‘South America’, ‘country’: ‘BR’, ‘country_name’: ‘Brazil’}
getCountry((ip_address) Returns the ISO 3166 country code of the input BR
getCountryName(ip_address) Returns the country name of the input IP address Brazil
getContinent(ip_address) Returns the continent shortcode of the input IP address SA
getContinentName(ip_address) Returns the name of the continent of the input IP address South America
getASN(ip_address) Returns the ASN (Autonomous System Number) of the input IP address AS31898
getASNName(ip_address) Returns the AS organization name of the input IP address Oracle Corporation
getASNDomain(ip_address) Returns the domain or the official website of the input IP address
getCountryDetails(ip_address) Returns all the available country-level information of the input IP address in a dictionary format {‘country’: ‘BR’, ‘country_name’: ‘Brazil’, ‘continent’: ‘SA’, ‘continent_name’: ‘South America’}
getASNDetails(ip_address) Returns all the available ASN-level information of the input IP address in a dictionary format {‘asn’: ‘AS31898’, ‘as_name’: ‘Oracle Corporation’, ‘as_domain’: ‘’}

Download options

Replace older downloaded database

The Client will download the free country_asn database if it doesn’t exist or if the path to the database file is not provided.

If the database exists in the default path, the download will be skipped but can still be forced to replace the old file by providing replace=True while initializing the Client object.

client = ipinfo_db.Client(access_token, replace=True)

Setup path for the database download

You can set up a custom path and filename where the database will be downloaded.

# Downloads the database in the current path with the filename country_asn.mmdb
client = ipinfo_db.Client(access_token, path="./country_asn.mmdb")

# Replaces the older country_asn.mmdb in the current directory
client = ipinfo_db.Client(access_token, path="./country_asn.mmdb", replace=True)


If you have any feedback with the library let us know in the comments.