SDKs overview

ip-api offers a straightforward RESTful API for IP geolocation lookups and proxy/VPN detection. While ip-api maintains a comprehensive API documentation, direct official Software Development Kits (SDKs) are not the primary integration method provided by the service itself. Instead, the developer community has created and maintains a variety of libraries across multiple programming languages to facilitate interaction with the ip-api service.

These community-contributed libraries abstract the underlying HTTP requests, handle URL construction, and parse the JSON, XML, or CSV responses from the ip-api endpoints. This approach allows developers to integrate IP lookup functionality using familiar language constructs, reducing the boilerplate code typically required for direct API interactions. The available libraries generally support both the free and paid tiers of the ip-api service, though specific features like HTTPS (required for commercial use) or batch requests may depend on the library's implementation.

Developers using ip-api can choose a library that aligns with their preferred programming language and project requirements. The following sections detail some of the notable community libraries and provide guidance on their installation and usage.

Official SDKs by language

ip-api primarily provides a direct HTTP API endpoint rather than maintaining a suite of official, language-specific SDKs. The service focuses on a simple, accessible API design that can be consumed directly by any HTTP client. This design choice aligns with the common practice for many lightweight web services, where the API's simplicity encourages direct integration or community-driven library development.

Consequently, there are no official SDKs published directly by ip-api for languages like Python, PHP, or JavaScript. Developers typically interact with the API using standard HTTP client libraries available in their language of choice, such as Python's requests, Node.js's axios or fetch, or PHP's Guzzle. The community has stepped in to create wrapper libraries that streamline these interactions, simplifying the process of querying the API and handling its responses.

Installation

Since ip-api primarily relies on community-contributed libraries, installation methods vary by language and library. The following table outlines some popular community libraries, their package names, and typical installation commands. Developers should consult the specific library's documentation for the most up-to-date and detailed installation instructions.

Language Library Name / Package Installation Command Maturity (Community Estimate)
Python ip-api (PyPI) pip install ip-api Stable
PHP giggsey/libphonenumber-for-php (Composer, includes IP lookup) composer require giggsey/libphonenumber-for-php Mature
JavaScript (Node.js) ip-api-js (npm) npm install ip-api-js Active
Go github.com/ip-api/go-ip-api go get github.com/ip-api/go-ip-api Active
Ruby ip-api-ruby (RubyGems) gem install ip-api-ruby Active
Java Direct HTTP client (e.g., OkHttp, HttpClient) (Add dependency to pom.xml or build.gradle) N/A (direct client)

For libraries not listed or for alternative approaches, developers can always fall back to making direct HTTP requests. Modern programming languages offer robust HTTP client libraries, such as the Fetch API in JavaScript or requests in Python, which simplify the process of sending requests and parsing responses from RESTful APIs like ip-api.

Quickstart example

The following example demonstrates how to perform a basic IP lookup using a common community Python library for ip-api. This snippet retrieves geolocation data for a specified IP address and prints some of the returned fields. For commercial use, ensure your plan supports HTTPS and include your API key if required by your chosen library or direct API call.

Python Quickstart

First, ensure you have the ip-api Python package installed:

pip install ip-api

Then, use the following Python code:

import ipapi

# Look up your own IP address
# response = ipapi.lookup()

# Or, look up a specific IP address
ip_address_to_lookup = "8.8.8.8" # Example: Google's Public DNS
response = ipapi.lookup(ip_address_to_lookup)

if response:
    print(f"IP Address: {response.get('query')}")
    print(f"Country: {response.get('country')}")
    print(f"City: {response.get('city')}")
    print(f"Latitude: {response.get('lat')}")
    print(f"Longitude: {response.get('lon')}")
    print(f"Organization: {response.get('org')}")
    print(f"ISP: {response.get('isp')}")
    print(f"ASN: {response.get('as')}")
else:
    print(f"Failed to retrieve IP information for {ip_address_to_lookup}")

JavaScript (Node.js) Quickstart

For Node.js, you might use a library like ip-api-js or make a direct HTTP request using axios or the built-in fetch API (available in newer Node.js versions or through a polyfill).

Using node-fetch (if fetch is not native):

npm install node-fetch
import fetch from 'node-fetch'; // For Node.js environments without native fetch

const ipAddressToLookup = '8.8.8.8'; // Example: Google's Public DNS
const apiUrl = `http://ip-api.com/json/${ipAddressToLookup}`;

async function getIpInfo() {
  try {
    const response = await fetch(apiUrl);
    if (!response.ok) {
      throw new Error(`HTTP error! status: ${response.status}`);
    }
    const data = await response.json();

    if (data.status === 'success') {
      console.log(`IP Address: ${data.query}`);
      console.log(`Country: ${data.country}`);
      console.log(`City: ${data.city}`);
      console.log(`Latitude: ${data.lat}`);
      console.log(`Longitude: ${data.lon}`);
      console.log(`Organization: ${data.org}`);
      console.log(`ISP: ${data.isp}`);
      console.log(`ASN: ${data.as}`);
    } else {
      console.error(`Error: ${data.message}`);
    }
  } catch (error) {
    console.error(`Failed to retrieve IP information: ${error}`);
  }
}

getIpInfo();

Remember that the free tier of ip-api is HTTP-only. For HTTPS, which is recommended for production environments and required for commercial use, a paid plan is necessary. When using a paid plan, ensure you include your API key in the request as specified in the ip-api documentation.

Community libraries

The ip-api ecosystem thrives on community contributions, with developers building and maintaining client libraries in various programming languages. These libraries often simplify common tasks like URL construction, error handling, and JSON response parsing, reducing the effort required to integrate the API into an application. While not officially supported by ip-api, these libraries are widely used and can be found on respective package managers or GitHub.

  • Python: The ip-api package on PyPI is a popular choice, providing a Pythonic interface to the API. It handles both single IP lookups and batch requests. Developers can find more information on the ip-api PyPI page.
  • PHP: While not a direct ip-api wrapper, libraries like giggsey/libphonenumber-for-php often incorporate IP geolocation features that can be configured to use ip-api. Dedicated wrappers are also available on Packagist.
  • JavaScript/Node.js: Several npm packages exist, such as ip-api-js, which abstract the HTTP requests and response handling for Node.js environments. For browser-side applications, direct fetch API calls are common, as outlined by the MDN Web Docs on Fetch API.
  • Go: Community modules like github.com/ip-api/go-ip-api provide Go language bindings, making it easier to integrate ip-api into Go applications.
  • Ruby: Gems like ip-api-ruby offer a wrapper for Ruby projects, simplifying IP lookup operations.
  • Java: While direct HTTP client usage (e.g., Apache HttpClient, OkHttp) is prevalent, developers may find community-contributed wrappers on Maven Central or GitHub that provide higher-level abstractions for ip-api.

When choosing a community library, consider factors such as its last update date, number of contributors, issue activity, and compatibility with your project's dependencies. Always review the library's source code and documentation to ensure it meets your security and functional requirements, especially when handling sensitive data or operating in production environments. For specific details on API usage, rate limits, and response formats, always refer to the official ip-api documentation.