Don't reinvent the wheel.
Abstract's APIs are production-ready now.
Abstract's suite of API's are built to save you time. You don't need to be an expert in email validation, IP geolocation, etc. Just focus on writing code that's actually valuable for your app or business, and we'll handle the rest.
Get started for freeGet an IP address in Python using Abstract's Geolocation API
Abstract API offers a free geolocation API that obtains a user's IP address and provides associated location information. A query to this API also provides information relevant to the user's location, such as their timezone, currency, and regional flag. This information makes it possible to customize the user experience across your platform with just a single data call.
To obtain a user's IP address and its associated location info, we can perform a simple call to Abstract's Geolocation API:
import requests
import json
# Your API key, available from your account page
YOUR_GEOLOCATION_KEY = 'your_key'
# URL to send the request to
request_url = 'https://ipgeolocation.abstractapi.com/v1/?api_key=' + YOUR_GEOLOCATION_KEY
response = requests.get(request_url)
result = json.loads(response.content)
print(result)
print('ip_address: {}'.format(result['ip_address']))
This approach provides a variety of geolocation information in addition to the user's IP address. If this data was requested for a user with the IP address 139.130.4.5, the call would return the following information:
{
'ip_address': '139.130.4.5',
'city': 'Sydney',
'city_geoname_id': 2147714,
'region': 'New South Wales',
'region_iso_code': 'NSW',
'region_geoname_id': 2155400,
'postal_code': '1001',
'country': 'Australia',
'country_code': 'AU',
'country_geoname_id': 2077456,
'country_is_eu': False,
'continent': 'Oceania',
'continent_code': 'OC',
'continent_geoname_id': 6255151,
'longitude': 151.209,
'latitude': -33.8688,
'security': {
'is_vpn': False
},
'timezone': {
'name': 'Australia/Sydney',
'abbreviation': 'AEDT',
'gmt_offset': 11,
'current_time': '12:17:29',
'is_dst': True
},
'flag': {
'emoji': '🇦🇺',
'unicode': 'U+1F1E6 U+1F1FA',
'png': 'https://static.abstractapi.com/country-flags/AU_flag.png',
'svg': 'https://static.abstractapi.com/country-flags/AU_flag.svg'
},
'currency': {
'currency_name': 'Australian Dollars',
'currency_code': 'AUD'
},
'connection': {
'autonomous_system_number': 1221,
'autonomous_system_organization': 'Telstra Corporation',
'connection_type': 'Corporate',
'isp_name': 'Telstra Internet',
'organization_name': None
}
}