SDKs overview

ipapi.com offers Software Development Kits (SDKs) and libraries designed to facilitate integration with its IP geolocation and lookup services. These SDKs simplify the process of making API requests, handling responses, and managing authentication within various programming environments. By encapsulating the complexities of HTTP requests and JSON parsing, SDKs allow developers to focus on application logic rather than low-level API interaction. The available SDKs support multiple programming languages, providing syntax and paradigms familiar to developers in those ecosystems.

The primary benefit of using an SDK is the reduction in boilerplate code required to interact with an API. This can lead to faster development cycles and fewer potential errors in API communication. ipapi.com's documentation provides specific installation instructions and code examples for each supported language, ensuring developers can quickly implement IP lookup functionalities into their projects. The API itself delivers data in JSON format, a widely supported data interchange format across web services as defined by the W3C.

Official SDKs by language

ipapi.com provides official SDKs for a range of popular programming languages, enabling developers to integrate IP geolocation capabilities directly into their applications. These SDKs are maintained to ensure compatibility with the latest API versions and typically offer a consistent interface across different languages.

Language Package/Library Installation Command (Example) Maturity
PHP ipapi/ipapi composer require ipapi/ipapi Stable
Python ipapi-python pip install ipapi-python Stable
Ruby ipapi-ruby gem install ipapi-ruby Stable
Node.js ipapi-node npm install ipapi-node Stable
Go go-ipapi go get github.com/ipapi/go-ipapi Stable
Java ipapi-java Maven/Gradle dependency (see documentation) Stable
C# IpApi.Client dotnet add package IpApi.Client Stable
Perl WebService::ipapi cpanm WebService::ipapi Stable

Installation

Installing ipapi.com's SDKs typically involves using the package manager specific to the programming language. The process generally requires adding the library as a dependency to your project, which then makes the SDK's functions and classes available for use. For detailed, language-specific instructions, developers should refer to the official ipapi.com documentation.

PHP

To install the PHP SDK, Composer is the recommended package manager. From your project directory, execute:

composer require ipapi/ipapi

Python

The Python SDK can be installed using pip, Python's package installer:

pip install ipapi-python

Ruby

For Ruby projects, the SDK is available as a gem. Install it using the gem command:

gem install ipapi-ruby

Node.js

Node.js developers can install the SDK via npm, the default package manager for Node.js:

npm install ipapi-node

Go

Go modules are used to manage dependencies. To install the Go SDK, use the go get command:

go get github.com/ipapi/go-ipapi

Java

For Java, dependencies are typically managed with Maven or Gradle. You would add the following to your pom.xml (Maven) or build.gradle (Gradle) file. Consult the ipapi.com Java SDK documentation for the latest dependency coordinates.

Maven Example:

<dependency>
    <groupId>com.ipapi</groupId>
    <artifactId>ipapi-java</artifactId>
    <version>1.0.0</version> <!-- Use the latest version -->
</dependency>

Gradle Example:

implementation 'com.ipapi:ipapi-java:1.0.0' // Use the latest version

C#

The C# SDK is available as a NuGet package. Install it using the .NET CLI:

dotnet add package IpApi.Client

Perl

Perl modules are often installed via CPAN. The cpanm utility is a common way to install modules:

cpanm WebService::ipapi

Quickstart example

The following examples demonstrate basic usage of ipapi.com SDKs to perform an IP lookup. These snippets assume you have already installed the respective SDK and have an API key, if required for your plan. For the most up-to-date and comprehensive examples, refer to the official ipapi.com API documentation.

Python Quickstart

This Python example shows how to retrieve geolocation data for a specified IP address:

import ipapi

# Replace 'YOUR_API_KEY' with your actual ipapi.com API key
# For free tier, an API key might not be strictly necessary for basic lookups,
# but it's good practice to include it if you have one.
api_key = 'YOUR_API_KEY'

# Look up a specific IP address
ip_address = '8.8.8.8' # Example: Google's Public DNS

try:
    # For paid plans, include api_key=api_key
    # For free tier, you might call ipapi.location(ip_address)
    location_data = ipapi.location(ip_address, api_key=api_key)

    if location_data:
        print(f"IP Address: {location_data.get('ip')}")
        print(f"Country: {location_data.get('country_name')}")
        print(f"City: {location_data.get('city')}")
        print(f"Latitude: {location_data.get('latitude')}")
        print(f"Longitude: {location_data.get('longitude')}")
        print(f"Organization: {location_data.get('organization')}")
    else:
        print(f"Could not retrieve data for IP: {ip_address}")
except Exception as e:
    print(f"An error occurred: {e}")

Node.js Quickstart

This Node.js example illustrates how to perform an asynchronous IP lookup:

const ipapi = require('ipapi-node');

// Replace 'YOUR_API_KEY' with your actual ipapi.com API key
const apiKey = 'YOUR_API_KEY';

// Look up a specific IP address
const ipAddress = '1.1.1.1'; // Example: Cloudflare DNS

ipapi.location(ipAddress, { apiKey: apiKey })
  .then(response => {
    if (response) {
      console.log(`IP Address: ${response.ip}`);
      console.log(`Country: ${response.country_name}`);
      console.log(`City: ${response.city}`);
      console.log(`Latitude: ${response.latitude}`);
      console.log(`Longitude: ${response.longitude}`);
      console.log(`Organization: ${response.organization}`);
    } else {
      console.log(`Could not retrieve data for IP: ${ipAddress}`);
    }
  })
  .catch(error => {
    console.error(`An error occurred: ${error.message}`);
  });

Community libraries

While ipapi.com provides official SDKs for major programming languages, the developer community may also contribute third-party libraries. These community-developed tools can offer alternative approaches, specialized functionalities, or support for languages not officially covered. When considering a community library, it is advisable to assess its maintenance status, documentation, and community support. Developers should also verify the library's compatibility with the current ipapi.com API version by checking the ipapi.com API reference and the library's project page.

Community libraries are often found on public code repositories like GitHub or language-specific package indexes (e.g., PyPI for Python, RubyGems for Ruby, npm for Node.js). Before integrating any third-party library, review its source code and licensing to ensure it meets project requirements and security standards. The Mozilla Developer Network's guide on web security can provide general context on secure API interactions.