How to use IP2Location.io API in Anaconda Code

Published: (December 3, 2025 at 04:32 AM EST)
2 min read
Source: Dev.to

Source: Dev.to

Intro

Anaconda Code is an Excel add‑in that lets you run Python or R code directly within Excel. It enables you to create custom Python functions for use in workbooks and provides package‑management features for adding or removing libraries, extending Excel’s capabilities. This makes it possible to query external APIs for data right inside Excel.

In this tutorial we’ll show how to use Anaconda Code to query the IP2Location.io API and display the results in your workbook. IP2Location.io offers a fast, accurate IP geolocation API for determining a visitor’s location and applying that data in various use cases.

Prerequisites

  • Anaconda Code installed (via the Anaconda Toolbox Excel add‑in).
  • An active IP2Location.io subscription (CORS support is available on the Starter plan and above). You can view and purchase a plan here: .

Steps to Use the IP2Location.io API in Anaconda Code

Step 1

In Excel, go to the Formulas tab and click the Code icon.

Step 1

Step 2

Click the Sign In button, then click it again to proceed.

Step 2

Step 3

Anaconda Code requires you to sign in before use. Log in with your Anaconda account or use Google, Microsoft, or GitHub.

Sign‑in page

Step 3

Step 4

If this is your first time, create an Anaconda Code cell. For this tutorial we’ll use the default settings—click Create Code Cell.

Step 4

Step 5

Open the Imports and Definitions panel and import the required library:

from pyodide.http import pyfetch

Step 6

Scroll to the end of the Code tab and paste the following async function. Replace YOUR_API_KEY with your actual IP2Location.io key.

async def iplio_query(ip: str, column: str | None = None):
    base_api = 'https://api.ip2location.io/?'
    api_key = 'YOUR_API_KEY'
    full_url = f'{base_api}key={api_key}&ip={ip}'
    resp = await pyfetch(full_url)
    data = await resp.json()
    if column is not None:
        return data[column]
    return data

Note: A paid plan is required to bypass the CORS limitation. See the CORS explanation here.

Step 7

Click Apply to save the code.

Step 8

Use the custom function in any worksheet cell. For example, if an IP address is in cell A14, enter:

=ANACONDA.IPLIO_QUERY(A14)

The function will return the full JSON response (or a specific column if you modify the call).

Conclusion

Anaconda Code brings the power of Python (or R) into Excel, allowing you to pull external data such as IP geolocation directly into your spreadsheets. This tutorial demonstrated how to query the IP2Location.io API, but the same approach works with any RESTful API.

For more tutorials, visit the IP2Location blog:

  • Find a free IP geolocation / proxy detection API:
  • Access a free IP geolocation / proxy detection database:
Back to Blog

Related posts

Read more »

How to Generate QR Codes in Python

A beginner-friendly tutorial exploring the Python 'qrcode' Package The post How to Generate QR Codes in Python appeared first on Towards Data Science....