IPinfo Python Library

5.5.0 · active · verified Thu Apr 16

The official Python client library for the IPinfo API, providing comprehensive IP address details like geolocation, ASN, company, privacy detection, and more. It offers both synchronous and asynchronous interfaces. As of version 5.5.0, it supports new IPinfo Core and Plus API features. The library maintains an active development status with regular, feature-driven releases.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the synchronous IPinfo client and perform lookups for your own IP address and a specific IP address. Ensure your IPinfo access token is provided either via an environment variable or directly in the code.

import os
from ipinfo.handler import Handler

# Get your IPinfo access token from environment variable or replace with your token
access_token = os.environ.get('IPINFO_TOKEN', 'YOUR_IPINFO_TOKEN') 

if not access_token or access_token == 'YOUR_IPINFO_TOKEN':
    print("Warning: Please set the IPINFO_TOKEN environment variable or replace 'YOUR_IPINFO_TOKEN' with your actual token.")
else:
    client = Handler(access_token)
    
    # Lookup your own IP address
    my_ip_details = client.getDetails()
    print(f"My IP: {my_ip_details.ip}")
    print(f"My city: {my_ip_details.city}, {my_ip_details.country_name}")
    
    # Lookup a specific IP address
    google_dns_ip = '8.8.8.8'
    google_details = client.getDetails(google_dns_ip)
    print(f"\nGoogle DNS IP: {google_details.ip}")
    print(f"Google DNS ISP: {google_details.org}")

view raw JSON →