A beginner-friendly Python package for fetching weather data, designed for educational use.
Project description
fetch-my-weather
A beginner-friendly Python package for fetching weather data, designed for educational use.
Features
- 🌤️ Easy access to weather data from wttr.in
- 🌙 Moon phase information
- 🗺️ Location-based weather (cities, airports, coordinates)
- 🌍 Multiple language support
- 📊 Text and PNG output formats
- 🚀 Built-in caching to be nice to the wttr.in service
- 🛡️ Beginner-friendly error handling (no exceptions)
- 📚 Designed for teaching Python and API interactions
- 🤖 LLM-ready with comprehensive LLM guide you can upload to AI assistants
Installation
pip install fetch-my-weather
Quick Start
import fetch_my_weather
# Get weather for your current location (based on IP)
current_weather = fetch_my_weather.get_weather()
print(current_weather)
# Get weather for Berlin in metric units
berlin_weather = fetch_my_weather.get_weather(location="Berlin", units="m")
print(berlin_weather)
# Get moon phase for a specific date
moon = fetch_my_weather.get_weather(is_moon=True, moon_date="2025-07-04")
print(moon)
Teaching Applications
fetch-my-weather is designed as a teaching tool for:
- Introducing API interactions in a beginner-friendly way
- Demonstrating HTTP requests without exception handling complexity
- Teaching caching concepts
- Working with different data formats (text and binary/PNG)
- Understanding URL construction and query parameters
- Processing and displaying weather data in applications
Mini-Projects
The package includes a collection of ready-to-use mini-projects in the docs/mini-projects/ directory:
- Beginner projects: Weather dashboard, multi-city checker, image saver
- Intermediate projects: Weather-based recommendations, forecast tracking, wallpaper changer
- Advanced projects: Notification system, data analyzer, home automation, weather-based game
These projects provide practical examples and serve as great teaching resources or starting points for your own applications.
Usage Guide
Getting Weather Data
import fetch_my_weather
# Basic usage - current location
weather = fetch_my_weather.get_weather()
# Specific location
nyc_weather = fetch_my_weather.get_weather(location="New York")
# Airport code
lax_weather = fetch_my_weather.get_weather(location="lax")
# Geographic coordinates
coord_weather = fetch_my_weather.get_weather(location="48.8567,2.3508")
# Compact view
compact_weather = fetch_my_weather.get_weather(view_options="0")
# Compact view + quiet (no city name in header)
compact_quiet = fetch_my_weather.get_weather(view_options="0q")
# Units: metric (default), USCS (u), or wind in m/s (M)
us_units = fetch_my_weather.get_weather(units="u")
# Different language
spanish = fetch_my_weather.get_weather(lang="es")
Getting Moon Phase Data
import fetch_my_weather
# Current moon phase
moon = fetch_my_weather.get_weather(is_moon=True)
# Moon phase for specific date
christmas_moon = fetch_my_weather.get_weather(is_moon=True, moon_date="2025-12-25")
# Moon with location hint (affects timing)
paris_moon = fetch_my_weather.get_weather(is_moon=True, moon_location_hint=",+Paris")
Getting PNG Weather Images
import fetch_my_weather
# Weather as PNG (returns bytes)
london_png = fetch_my_weather.get_weather(location="London", is_png=True)
# Save PNG to file
with open("london_weather.png", "wb") as f:
f.write(london_png)
# PNG with options (transparency)
transparent_png = fetch_my_weather.get_weather(location="Tokyo", is_png=True, png_options="t")
Configuration Settings
import fetch_my_weather
# Change cache duration (in seconds, 0 to disable)
fetch_my_weather.set_cache_duration(1800) # 30 minutes
# Clear the cache
fetch_my_weather.clear_cache()
# Set a custom user agent
fetch_my_weather.set_user_agent("My Weather App v1.0")
Error Handling
import fetch_my_weather
# fetch-my-weather never raises exceptions, it returns error messages as strings
result = fetch_my_weather.get_weather(location="NonExistentPlace12345")
# Check if result is an error message
if isinstance(result, str) and result.startswith("Error:"):
print(f"Something went wrong: {result}")
else:
print("Weather data:", result)
Complete Parameter Reference
The get_weather() function accepts these parameters:
| Parameter | Type | Description |
|---|---|---|
location |
str | Location identifier (city name, airport code, coordinates, etc.) |
units |
str | Units system: m (metric, default), u (US/imperial), M (wind in m/s) |
view_options |
str | Display options: 0-3 (forecast days), n (narrow), q (quiet), etc. |
lang |
str | Language code (e.g., en, fr, es, ru, zh-cn) |
is_png |
bool | If True, return PNG image as bytes instead of text |
png_options |
str | PNG-specific options: p (padding), t (transparency), etc. |
is_moon |
bool | If True, show moon phase instead of weather |
moon_date |
str | Date for moon phase in YYYY-MM-DD format (with is_moon=True) |
moon_location_hint |
str | Location hint for moon phase (e.g., ,+US, ,+Paris) |
Documentation
📚 Full documentation is now live at michael-borck.github.io/fetch-my-weather!
The documentation includes:
- 📘 Detailed user guide with examples
- 🛠️ Mini-projects for learning (beginner to advanced)
- 🎓 Teaching resources for educators
- 📋 Technical documentation for developers
AI Assistant Integration
🤖 This package includes an LLM guide specifically designed for AI assistants.
To use with AI assistants:
- Download the LLM-GUIDE.md file
- Upload it to your AI assistant (like Claude, ChatGPT, etc.)
- The AI can now help you use the package more effectively
License
MIT License - see the LICENSE file for details.
Contributors
This project is maintained by Michael Borck with contributions from various individuals. See AUTHORS.md for a complete list of contributors.
Acknowledgments
This package is a wrapper around the amazing wttr.in service created by Igor Chubin. Please be respectful of the wttr.in service by not making too many requests.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fetch_my_weather-0.1.3.tar.gz.
File metadata
- Download URL: fetch_my_weather-0.1.3.tar.gz
- Upload date:
- Size: 13.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a656eb6bc87020f6271d1019b2d92d49adc2f29cea4cd3587039c10d92361476
|
|
| MD5 |
586cd1cb3b9bdd273316228e1ec9b0cf
|
|
| BLAKE2b-256 |
5f54ba7268ec1a9acacadce6552369fb1ec31dab14a02c53269dcc644d2368e3
|
File details
Details for the file fetch_my_weather-0.1.3-py3-none-any.whl.
File metadata
- Download URL: fetch_my_weather-0.1.3-py3-none-any.whl
- Upload date:
- Size: 9.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dd1bf26b0513cfa665e3a2c2faff1fe08d6eac503e3be91284de34a6dde2fcb0
|
|
| MD5 |
b4f1039fb77bb87de9f325205f7638b0
|
|
| BLAKE2b-256 |
b773e28ded5a092946125be16b93b4d8477a3175d305ef16f1fa373c6737ef40
|