Geolocate an IP Address to a Street Address in Python

To better understand your client base and track any incoming threats to your sites, it is imperative to know where your users are located. Furthermore, if you are designing a program or application that is dependent on location information, this can help hone your system to provide an accurate result. The following function will let you to geolocate an IP Address to its street address and return the country and country code, street address, city name, region name, and Zip code.

Image for post
Image for post

To use this API, you can run this command to install the SDK:

pip install cloudmersive-validate-api-client

Then, you can call the function:

from __future__ import print_function
import time
import cloudmersive_validate_api_client
from import ApiException
from pprint import pprint
# Configure API key authorization: Apikey
configuration = cloudmersive_validate_api_client.Configuration()
configuration.api_key['Apikey'] = 'YOUR_API_KEY'
# create an instance of the API class
api_instance = cloudmersive_validate_api_client.IPAddressApi(cloudmersive_validate_api_client.ApiClient(configuration))
value = 'value_example' # str | IP address to geolocate, e.g. \"\". The input is a string so be sure to enclose it in double-quotes.
# Geolocate an IP address to a street address
api_response = api_instance.i_p_address_geolocate_street_address(value)
except ApiException as e:
print("Exception when calling IPAddressApi->i_p_address_geolocate_street_address: %s\n" % e)

You can get your free API Key from Cloudmersive. This will give you access to 800 monthly calls across our entire API Library.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store