Libraries & APIs · Lesson 53 of 76
Working with APIs
An API lets your program ask another service for data over the internet — weather, exchange rates, and so on. The reply almost always comes back as JSON, which is just text shaped like Python dicts and lists.
On a real machine you'd fetch it with the requests package:
import requests
reply = requests.get("https://api.example.com/weather?city=Lagos")
data = reply.json()
print(data["temp_c"])
That needs internet, so it won't run in the browser box. But the important skill — turning a JSON reply into Python you can use — runs fine right here with the built-in json module:
Python
Your turn: change the city and temperature in reply_text, then run it.
You’re reading for free. Sign in to keep your progress and earn a certificate when you finish.Sign in to keep my progress →