Eduarn – Online & Offline Training with Free LMS for Python, AI, Cloud & More

Saturday, November 15, 2025

🌦️ Build Your Own Open-Source Weather API Using Python, FastAPI, and Open-Meteo in Windows 11


 

No API Keys. 100% Free. Runs on Windows, Linux, or macOS.

If you’ve ever wanted to build a weather service that you fully control—without relying on paid providers—this guide is for you. Today we’ll build a fully open-source weather API using:

✔ Python
✔ FastAPI
✔ Uvicorn
✔ Open-Meteo (free, no API key)

This weather server runs locally on any computer and can be extended to power automation tools, chatbots, dashboards, or IoT projects.

Let’s get started!


🚀 Why Open-Source Instead of Claude/Proprietary MCP?

In the MCP ecosystem, servers are often built to integrate with specific applications like Claude Desktop. But not everyone wants to depend on closed-source platforms.

This tutorial shows how to build a fully standalone weather API, powered only by open-source tools:

  • FastAPI → modern Python web framework

  • Uvicorn → lightning-fast ASGI server

  • Open-Meteo API → real-time global weather data

  • httpx → async HTTP client

The result?
A clean, extensible, open-source weather microservice you can run anywhere.


🖥️ Step 1 — Install Requirements (Windows / macOS / Linux)

Open a terminal or PowerShell window and install dependencies:

pip install fastapi uvicorn httpx

That’s all you need.


🏗️ Step 2 — Create the Project File

Create a new directory:

mkdir weather-server cd weather-server

Then create:

server.py

Paste in the full working code:

from typing import Any import httpx from fastapi import FastAPI # Initialize FastAPI app app = FastAPI() # Constants OPENMETEO_API_BASE = "https://api.open-meteo.com/v1" USER_AGENT = "weather-mcp/1.0" # Helper function to interact with the Open-Meteo API async def make_openmeteo_request(url: str) -> dict[str, Any] | None: """Make a request to the Open-Meteo API with proper error handling.""" headers = { "User-Agent": USER_AGENT, "Accept": "application/json", } async with httpx.AsyncClient() as client: try: response = await client.get(url, headers=headers, timeout=30.0) response.raise_for_status() return response.json() except Exception: return None # ----------------------------- # Endpoint - Get Current Weather # ----------------------------- @app.get("/current-weather") async def get_current_weather(latitude: float, longitude: float) -> dict: """Get current weather data for a specified latitude/longitude.""" url = ( f"{OPENMETEO_API_BASE}/forecast" f"?latitude={latitude}&longitude={longitude}" "&current=temperature_2m,is_day,showers,cloud_cover,wind_speed_10m," "wind_direction_10m,pressure_msl,snowfall,precipitation," "relative_humidity_2m,apparent_temperature,rain,weather_code," "surface_pressure,wind_gusts_10m" ) data = await make_openmeteo_request(url) if not data: return {"error": "Unable to fetch current weather data for this location."} return data # ----------------------------- # Endpoint - Get Weather Forecast # ----------------------------- @app.get("/forecast") async def get_forecast(latitude: float, longitude: float, days: int = 3) -> dict: """Get forecast for next X days.""" url = ( f"{OPENMETEO_API_BASE}/forecast" f"?latitude={latitude}&longitude={longitude}" f"&hourly=temperature_2m,precipitation,cloud_cover" f"&forecast_days={days}" ) data = await make_openmeteo_request(url) if not data: return {"error": "Unable to fetch forecast."} return data # ----------------------------- # Endpoint - Get Location by Name # ----------------------------- @app.get("/location") async def get_location(query: str) -> dict: """Search for a city/place name and get coordinates.""" url = f"https://geocoding-api.open-meteo.com/v1/search?name={query}&count=5" data = await make_openmeteo_request(url) if not data: return {"error": "Location not found."} return data

▶️ Step 3 — Run Your Server

Start the server using Uvicorn:

uvicorn server:app --reload

You’ll see:

Uvicorn running on http://127.0.0.1:8000

Open your browser and test:

✔ Current Weather

http://127.0.0.1:8000/current-weather?latitude=40.7128&longitude=-74.0060

✔ Forecast

http://127.0.0.1:8000/forecast?latitude=40.7128&longitude=-74.0060&days=3

✔ Location Search

http://127.0.0.1:8000/location?query=London

📘 Step 4 — Use the Interactive Dashboard

FastAPI provides automatic documentation.

Open:

http://127.0.0.1:8000/docs

You now have:

  • A UI for testing all endpoints

  • Auto-generated schema

  • Live API explorer

No additional setup. It just works.


🧩 Step 5 — Why This Matters

This small project demonstrates how you can:

  • Build useful microservices with only open-source tools

  • Consume real-time weather data without API keys

  • Extend the API into dashboards, chatbots, IoT devices, and more

  • Deploy the service anywhere (Docker, VPS, Raspberry Pi, etc.)

It’s clean, lightweight, and completely free to use.


🎉 Final Thoughts

With Python, FastAPI, and Open-Meteo, you now have a fully functioning open-source weather server that you can run locally or deploy to the cloud.

This is a perfect foundation for:

  • AI integrations

  • Automation scripts

  • Custom user interfaces

  • Smart home systems

  • Education and learning projects



📚 Need Online, Retail, or Corporate Training?

If you want to master Python, APIs, cloud, AI, full-stack development, DevOps, or corporate-level tech skills, learn with the best trainers available.

Get professional online training, retail programs, or corporate upskilling from experts:

👉 www.eduarn.com

Your learning, your success — powered by world-class trainers.

No comments:

Post a Comment

Free Python Webinar for Data Analysis: Learn Real-World Python Skills from Industry Experts (2026 Guide)

  Why Most Python Learners Fail (And How You Can Avoid It) You’ve watched hours of Python tutorials. You’ve bookmarked dozens of YouTube v...