What is an API?

It’s like visiting a website, but for code.

When you open a website, your browser asks a server for a page and the server sends one back. That’s a conversation. A question goes out, an answer comes back.

An API (short for Application Programming Interface, though the name is fancier than the idea) is the same conversation. Only this time your code is the one asking, and what comes back isn’t a webpage. It’s raw data your code can work with.

You + browser
Website
Your code
API

APIs are how programs talk to each other.

Why Excel users care

An API is just a URL your code can call. There’s one for almost anything you might want to pull into Excel or fire off from a sheet:

Each one has its own URL. Each one returns its own shape of data. They all share one rule: your code asks, the server answers.

Try one yourself

Different APIs have different URLs, and they answer in different shapes. Pick one of these to see what changes when you ask differently. The first one is what our course uses.

A big dictionary. One rate for every currency, relative to the US Dollar.

https://api.pythonandvba.com/exchange/latest?base=USD

The first three answers come back as JSON, the format most APIs use. The last one comes back as a CSV file. The shape of the answer is up to whoever built the API. Your code just has to know what to expect.

Calling it from Python

Here’s the same idea in code. Three steps: ask, read, use. The course capstone uses this exact pattern to convert every row of a sales table to USD.

import pandas as pd

# The exchange rate URL (the first option above)
url = "https://api.pythonandvba.com/exchange/latest?base=USD"

# Ask the API and read the answer
data = pd.read_json(url, typ="series")

# Pick the rate you need
eur_rate = data["rates"]["EUR"]
print(eur_rate)   # e.g. 0.85

Here’s what happens to the data, step by step:

Step 1 of 4

That’s the whole API workflow in Python. Once you’ve got the data in a variable, it’s yours to do anything with: drop it into a cell, multiply it across a column, or feed it into a pivot.

One catch in xlwings Lite: CORS

Because xlwings Lite runs your Python code inside the browser, the browser’s security rules apply. The big one is called CORS (short for Cross-Origin Resource Sharing). In plain English: the browser refuses to call APIs that haven’t explicitly said “yes, browsers from anywhere can call me.”

In practice:

Check before you build. Paste the API’s URL into your browser’s address bar. If you see data on the page, you can call it from Lite. If the browser blocks it or tries to download a file, you can’t.

If an API blocks you in Lite, you have two options:

Full technical details: lite.xlwings.org/web_requests