Your Programs Only Know What You Type In
Every program you have written so far only knows what you typed into it: the budget tracker knew your expenses because you listed them, the flashcard quiz knew the questions because you wrote them. Real apps work differently — the weather app on your phone has never looked at the sky. It asks a weather service, and the service answers. That question is called an API call — the skill that turns your little programs into programs that talk to the real world.
An API — application programming interface — is just an agreement: you send a request to a web address, and a program on the other end sends back an answer. No server, no account — for the free weather API in this article, the whole conversation is one web address and one reply.
An API Call Has Three Parts
First, the URL — the address and the question in one line. The address is api.open-meteo.com, and the question is written as extra pieces after a question mark: latitude=17.385&longitude=78.4867 says "Hyderabad", and current=temperature_2m,weather_code says "I want the temperature and the weather code right now". Change the numbers, change the city.
Second, the answer, which comes back as JSON — JavaScript Object Notation, which is just a set of nested boxes with labels: a box called "current" holding "temperature_2m": 20.4 and "weather_code": 0. You do not need to memorise the shape: print it, read it, then pick out the boxes you need.
Third, your code picks out the value and does something with it. data["current"]["temperature_2m"] walks one box at a time: open "current", then read "temperature_2m". That is the whole trick — the rest is detail you can look up when you need it.
Try It: Ask the Weather in 30 Lines
Paste it into the browser editor and run it — the first line prints the weather where the numbers point, right now.
# weather.py - your first API call (no key, no signup)
import json
import urllib.request # Open-Meteo is a free weather API: no key, no account, no server.
# The URL is the question: "current temperature in Hyderabad?"
URL = ( "https://api.open-meteo.com/v1/forecast" "?latitude=17.385&longitude=78.4867" "¤t=temperature_2m,weather_code"
) # If the network is blocked, this sample is the same shape
# as the real answer - so the rest still runs and teaches.
SAMPLE = { "current": {"temperature_2m": 24.5, "weather_code": 2}
} WEATHER = { 0: "clear sky", 1: "mostly clear", 2: "partly cloudy", 3: "overcast", 45: "foggy", 51: "light drizzle", 61: "light rain", 63: "rain", 71: "light snow", 95: "thunderstorm",
} def fetch_weather(url): try: with urllib.request.urlopen(url, timeout=10) as response: return json.load(response) except Exception: print("Live request failed - using the sample answer instead.") return SAMPLE def describe(data): current = data["current"] temp = current["temperature_2m"] code = current["weather_code"] words = WEATHER.get(code, "weather code %s" % code) return "Right now in Hyderabad it is %.1f C - %s." % (temp, words) print(describe(fetch_weather(URL)))
print(describe(SAMPLE))
print("Code 0 means %s; code 61 means %s." % (WEATHER[0], WEATHER[61]))
print("Unknown code 99:", describe({"current": {"temperature_2m": 20.0, "weather_code": 99}}))The output is four lines. The first line is live: when I ran it, it printed "Right now in Hyderabad it is 20.4 C - clear sky." — yours will show whatever the weather is when you run it. That is the point: the data is not in your code, it is in the world, and your code fetched it. The second line is the sample answer, 24.5 C and partly cloudy — describe() works with no network at all. The third line proves the code table works, and the fourth is the safety net: an unknown code prints "weather code 99" instead of crashing.
fetch_weather() tries the live request inside try, and if anything goes wrong — no network, blocked wifi, a typo in the URL — except catches it, says so, and hands back the sample: try the real thing, have a plan for failure, never crash silently. describe() then does the same job on either answer, because both have the same shape.
Reading the Answer: JSON Is Just Nested Boxes
If the shape confuses you, print the whole answer first — print(data) shows you every box and label. Then read from the outside in: data is a box labelled "current", holding temperature_2m and weather_code. Square brackets open a labelled box, one bracket per level, and a KeyError means you asked for a label that is not there — print the answer again and read the labels.
Why is the weather a number instead of words? Because numbers travel well: code 2 means "partly cloudy" in every language, and it is shorter to send than a sentence. APIs do this everywhere. That is why the example keeps a small WEATHER dictionary: it translates codes into words, and a new code costs one line — the program grows by data, not by rewriting.
Make It Yours: Three Upgrades
First, your city: Open-Meteo's free geocoding API answers "Hyderabad" with 17.38 and 78.46 — swap the two numbers in the URL and run it again. Second, ask for the week: add &daily=temperature_2m_max,temperature_2m_min&forecast_days=3 to the URL and read data["daily"]["temperature_2m_max"], a list of daily highs. Third, test before you fetch: write down what describe(SAMPLE) should print before you run it, the way the first-test habit teaches — if the sample line is right, your function is right, and any live problem is in the request, not the logic. One small change and one run each: the URL is the question, the answer can hold lists, and a function you can check with a sample is one you can trust with live data.
From a Snippet to a Portfolio Piece
When it prints your city's real weather, save it as a snippet called "first-api-call" with a one-line note: "calls the Open-Meteo API, reads JSON, turns weather codes into words." That note turns saved code into study material — your snippet library is your revision notes. Then push it to GitHub with a short README, following the portfolio guide: a live API project says what a tutorial copy cannot — your code talks to the real world.
And it is the start of a bigger path: the same three parts — URL, JSON, pick the value — work for any API you meet later. Once you have made one call, the second one is just a different address — and the Lab courses build the same ideas into a full learning path.
When the Free Plan Runs Out
Trying API ideas burns executions fast — run after every change, test the sample, re-run after each upgrade. Free gives you 20 executions a day, 10 AI requests a day, 10 saved snippets, 3 private snippets, and 3 collaborators per snippet — enough for one careful project a day. When you start building daily, that is the upgrade moment: Pro is $9/month or $69/year — unlimited saved snippets and executions, 100 AI requests a day, 10 collaborators per snippet, unlimited private snippets, and GitHub integration, which Free does not include. Team ($19/user/month, or $15/user/month billed annually) covers a class or study group building projects together — see the pricing page.
Your next step is tonight: paste the code above into the browser editor, run it, and watch the first line print the weather where you live. Then change the two numbers to your own city, run it again, and save it as a snippet called "first-api-call". Tomorrow, add the daily forecast — one parameter, one list of highs. The first time your code asks the internet a question and gets an answer back, you stop writing programs that only know what you typed.