We’ve just published four new official client libraries, so you can now get up and running with IP geolocation quickly in:
- Go
- PHP
- Python
- Java
All powered by our high-accuracy IP geolocation, threat, and privacy detection API.
Use your favorite package manager to install the library, and then follow the quick start guide in the library’s README to get started — or scroll down for some quick snippets!
Language | Package | GitHub |
---|---|---|
Python | python-iplocate on PyPi | iplocate/python-iplocate |
Java | java-iplocate on Maven Central | iplocate/java-iplocate |
PHP | php-iplocate on Packagist | iplocate/php-iplocate |
Go | go-iplocate on pkg.go.dev | iplocate/go-iplocate |
These new libraries join our existing packages for:
- Ruby (iplocate/ruby-iplocate)
- Node.js (iplocate/node-iplocate)
Read on for some quick examples of how to use the libraries.
Look up an IP address’s country and city in Python
For more detailed examples, see the python-iplocate README.
from iplocate import IPLocateClient
# Create a client with your API key
# Get your free API key from https://iplocate.io/signup
client = IPLocateClient(api_key="your-api-key")
# Look up an IP address
result = client.lookup("8.8.8.8")
print(f"IP: {result.ip}")
if result.country:
print(f"Country: {result.country}")
if result.city:
print(f"City: {result.city}")
print(location)
Look up an IP address’s country and city in Go
For more detailed examples, see the go-iplocate README.
import (
"fmt"
"log"
"github.com/iplocate/go-iplocate"
)
func main() {
// Create a new client with default HTTP client
// Get your free API key from https://iplocate.io/signup
client := iplocate.NewClient(nil).WithAPIKey("your-api-key")
// Look up an IP address
result, err := client.Lookup("8.8.8.8")
if err != nil {
log.Fatal(err)
}
fmt.Printf("IP: %s\n", result.IP)
if result.Country != nil {
fmt.Printf("Country: %s\n", *result.Country)
}
if result.City != nil {
fmt.Printf("City: %s\n", *result.City)
}
}
Look up an IP address’s country and city in PHP
For more detailed examples, see the php-iplocate README.
<?php
use IPLocate\IPLocate;
// Create a client with your API key
// Get your free API key from https://iplocate.io/signup
$client = new IPLocate('your-api-key');
// Look up an IP address
$result = $client->lookup('8.8.8.8');
echo "IP: {$result->ip}\n";
if ($result->country) {
echo "Country: {$result->country}\n";
}
if ($result->city) {
echo "City: {$result->city}\n";
}
Look up an IP address’s country and city in Java
For more detailed examples, see the java-iplocate README.
// Create a new client with your API key
// Get your free API key from https://iplocate.io/signup
IPLocateClient client = new IPLocateClient("your-api-key");
// Look up an IP address
IPLocateResponse result = client.lookup("8.8.8.8");
System.out.println("IP: " + result.getIp());
if (result.getCountry() != null) {
System.out.println("Country: " + result.getCountry());
}
if (result.getCity() != null) {
System.out.println("City: " + result.getCity());
}
Try our Model Context Protocol (MCP) server
Plus, we’ve just released our official MCP server, so you can quickly integrate IPLocate into your AI workflows.
See it on GitHub: https://github.com/iplocate/mcp-server-iplocate
Get paid to write a new SDK or integration
If you are a developer and your favorite programming language or framework is missing from our collection of official libraries, why not write one?
We will happily pay you for your time! Please see our Build for IPLocate page for more details.