If you want to fetch live weather data in your Python project without paying for an API key, you're in the right place. The Open-Meteo API is completely free, requires no signup, and works straight out of the box. This free weather API Python tutorial shows you exactly how to pull real weather data in under 20 lines of code — and then build on it from there.
Most weather APIs lock the useful stuff behind a paywall or make you jump through hoops just to grab a key. Open-Meteo skips all of that. It's an open-source weather API that gives you hourly and daily forecasts for any location on Earth — no credit card, no account, no rate-limit headaches for normal usage.
So whether you're building a personal dashboard, automating a script, or just learning how APIs work, this guide walks you through every step. By the end, you'll have a working Python script that fetches real weather data from anywhere in the world.
What Is the Open-Meteo API?
Open-Meteo is a free, open-source weather API that provides accurate meteorological data sourced from national weather services like NOAA, ECMWF, and Deutscher Wetterdienst. You don't need an API key. You don't need to register. You just call the endpoint with the coordinates you want, and it returns JSON.
The base URL is:
https://api.open-meteo.com/v1/forecast
From there, you pass latitude, longitude, and the specific weather variables you want — temperature, wind speed, humidity, precipitation, and more. That's it. One URL, clean JSON response, zero friction.
Why Use Open-Meteo for Python Projects?
Here's the thing — most free tiers on weather APIs are frustratingly limited. You get 50 or 60 calls a day, then you're cut off. Open-Meteo doesn't work that way. It handles up to 10,000 daily requests for free without throttling your project.
It's also dead simple to work with. The response is clean JSON, the documentation is clear, and it plays nicely with Python's requests library. If you're looking for a beginner weather API Python project to practice real HTTP calls, this is the one to start with. No configuration headaches. No token refresh flows. Just you, Python, and an API that works.
Step-by-Step Tutorial: Fetch Weather Data with Python
Step 1: Install the Required Library
You only need the requests library. If you don't have it already, run this in your terminal:
pip install requests
That's all the setup you need. No virtual environment required for a quick test, though it's always a good habit.
Step 2: Find Your Latitude and Longitude
Open-Meteo uses coordinates instead of city names. You can find coordinates for any city at latlong.net or just Google [city name] latitude longitude. For this tutorial, we'll use New York City: latitude 40.7128, longitude -74.0060.
Step 3: Make Your First API Call
import requests
url = 'https://api.open-meteo.com/v1/forecast'
params = {
'latitude': 40.7128,
'longitude': -74.0060,
'current_weather': True
}
response = requests.get(url, params=params)
data = response.json()
print(data['current_weather'])
Run that, and you'll get back something like this:
{'temperature': 18.3, 'windspeed': 14.2, 'weathercode': 3, 'time': '2024-01-15T14:00'}
That's live weather data — pulled for free, no key needed. Pretty satisfying for 10 lines of code.
Step 4: Request Hourly and Daily Forecasts
Want more than just current conditions? You can request hourly and daily forecasts by adding a few more parameters:
params = {
'latitude': 40.7128,
'longitude': -74.0060,
'hourly': 'temperature_2m,precipitation,windspeed_10m',
'daily': 'temperature_2m_max,temperature_2m_min,precipitation_sum',
'timezone': 'America/New_York'
}
response = requests.get(url, params=params)
data = response.json()
hourly_temps = data['hourly']['temperature_2m']
daily_max = data['daily']['temperature_2m_max']
print('Hourly temperatures:', hourly_temps[:5])
print('Daily max temps:', daily_max)
The timezone parameter is important here. Without it, times come back in UTC. Set it to your local timezone and the timestamps make sense immediately.
Step 5: Build a Clean, Reusable Weather Function
Let me show you a cleaner version that wraps everything into a function you can drop into any project:
import requests
def get_weather(lat, lon):
url = 'https://api.open-meteo.com/v1/forecast'
params = {
'latitude': lat,
'longitude': lon,
'current_weather': True,
'hourly': 'temperature_2m,precipitation',
'timezone': 'auto'
}
response = requests.get(url, params=params)
data = response.json()
current = data['current_weather']
print(f"Temperature: {current['temperature']}°C")
print(f"Wind Speed: {current['windspeed']} km/h")
print(f"Weather Code: {current['weathercode']}")
get_weather(40.7128, -74.0060)
The timezone: auto setting tells Open-Meteo to detect the timezone from the coordinates automatically. Use that and you'll almost never need to hardcode a timezone string again.
Understanding the API Output
The response from Open-Meteo comes back as a JSON object. The keys you'll use most often are current_weather for real-time conditions, hourly for per-hour forecasts, and daily for full-day summaries.
Weather codes follow the WMO standard. Code 0 is clear sky. Code 3 is overcast. Codes above 60 usually indicate rain. You can find the full lookup table in the Open-Meteo documentation. It's worth bookmarking if you're building anything that displays weather conditions to users.
Error Handling: What Can Go Wrong?
API calls don't always work perfectly. Networks fail. Coordinates can be wrong. Parameters might be misspelled. Here's how to handle those cases properly so your script doesn't crash when something goes sideways:
import requests
def get_weather_safe(lat, lon):
url = 'https://api.open-meteo.com/v1/forecast'
params = {
'latitude': lat,
'longitude': lon,
'current_weather': True,
'timezone': 'auto'
}
try:
response = requests.get(url, params=params, timeout=10)
response.raise_for_status()
data = response.json()
if 'current_weather' not in data:
print('No weather data found in response.')
return None
return data['current_weather']
except requests.exceptions.Timeout:
print('Request timed out. Try again.')
except requests.exceptions.ConnectionError:
print('Network error. Check your connection.')
except requests.exceptions.HTTPError as e:
print(f'HTTP error: {e}')
except Exception as e:
print(f'Something went wrong: {e}')
return None
weather = get_weather_safe(40.7128, -74.0060)
if weather:
print(weather)
The timeout=10 argument is easy to forget, but it matters. Without it, your script can hang forever if the server doesn't respond. The raise_for_status() call catches 4xx and 5xx HTTP errors before you try to parse the response body. And checking for the key before accessing it stops a KeyError from taking your whole script down.
Real-World Use Cases
- Personal Weather Dashboard: Build a simple CLI dashboard that shows today's forecast every morning when you open your terminal. Combine it with a cron job and it runs automatically.
- Smart Home Automation: Trigger actions based on weather — close smart blinds when it's sunny, or send a rain alert before your morning run via a Telegram bot.
- Data Logging and Analysis: Log daily temperature and precipitation data to a CSV file over months, then analyze seasonal trends with pandas or matplotlib.
- Travel Planning App: Let users enter a city name, convert it to coordinates using the free Open-Meteo Geocoding API, then display a 7-day forecast before they book a trip.
- Agriculture and Outdoor Scheduling: Use wind speed and precipitation data to automatically flag bad days for spraying or outdoor work — genuinely useful for small farm automation scripts.
Open-Meteo vs Other Free Weather APIs
| Feature | Open-Meteo | OpenWeatherMap Free | WeatherAPI Free |
|---|---|---|---|
| API Key Required | No | Yes | Yes |
| Free Requests/Day | 10,000+ | 1,000 | 1,000,000 (capped features) |
| Historical Data | Yes | Limited | Yes (limited) |
| Forecast Range | 16 days | 5 days | 14 days |
| Open Source | Yes | No | No |
| Rate Limits | Generous | Strict | Moderate |
For anyone learning how to fetch weather data free of charge, Open-Meteo wins on almost every dimension that matters for side projects and learning.
FAQ
Do I need an API key for Open-Meteo?
No. Open-Meteo is completely free and doesn't require registration or an API key for standard usage. Just call the URL directly from your Python script.
Is Open-Meteo accurate enough for real projects?
Yes. It pulls data from reputable national weather services like NOAA and ECMWF. Accuracy is solid for most practical use cases — dashboards, planning tools, automation scripts.
Can I use Open-Meteo for commercial projects?
The free tier is intended for non-commercial use. If you're building a commercial product, check their website for paid commercial licensing options. The pricing is fair compared to competitors.
How do I get weather by city name instead of coordinates?
Open-Meteo doesn't support city names directly on the forecast endpoint. Use the Open-Meteo Geocoding API — also completely free — to convert a city name to coordinates, then pass those to the forecast API.
What weather variables does Open-Meteo support?
Quite a few. Temperature, humidity, precipitation, wind speed, UV index, soil temperature, cloud cover, visibility, and more. The full list is in their official docs at open-meteo.com.
Does it work with Python 3?
Yes, any Python 3.6 or newer works fine. Just install requests and you're good to go. No special dependencies or version quirks to worry about.
Can I fetch historical weather data too?
Yes. Open-Meteo has a separate free historical weather API endpoint at https://archive-api.open-meteo.com/v1/archive that goes back decades. Same format, same simplicity.
Wrapping Up
Open-Meteo is one of the most practical free tools available for Python developers who want to work with weather data. No signup, no key, clean JSON responses, and a generous daily request limit. It's hard to beat for learning and building real things.
This free weather API Python tutorial walked you through your first API call, building a reusable function, handling errors properly, and understanding the output format. If you work through these examples and tweak them, you'll get comfortable with API calls fast — and the skills carry over to every other API you'll ever use.
Start with the simple call. Get it working. Then build something you actually want to use.
Want to keep going? Free API Hub has dozens of free APIs across weather, finance, geography, sports, and more — all documented, all free, and all ready for your next Python project. Browse the full API directory at Free API Hub and find your next build.







