A Python wrapper for the OpenWeatherMap API to fetch weather data.
Project description
OpenWeather Wrapper
OpenWeather Wrapper is a Python package that provides an easy-to-use interface for interacting with various weather APIs like OpenWeatherMap and WeatherStack. It allows users to retrieve current weather data, hourly forecasts, and 7-day weather forecasts for a specified city or geographical coordinates (latitude and longitude). The package also supports data caching, error handling, and data visualization.
Features
- Weather Data Fetching: Fetch current weather data by city name or geographical coordinates (latitude/longitude).
- Hourly Forecast: Retrieve hourly weather forecast data for the next 24 hours.
- 7-Day Forecast: Get the 7-day weather forecast.
- Error Handling: Custom error handling for API-related issues.
- Data Caching: Cache weather data to reduce API calls using
requests_cache. - Data Visualization: Plot temperature data for the next 24 hours using
matplotlib.
Installation
You can install the package using pip (once the package is registered on PyPi) or by cloning the repository:
Option 1: Install from PyPi (once available)
pip install openweather-wrapper
Option 2: Install from GitHub (for local development)
git clone https://github.com/yourusername/openweather-wrapper.git
cd openweather-wrapper
pip install .
Requirements
- Python 3.6 or higher
- requests
- requests_cache
- matplotlib
You can install the required dependencies using pip:
pip install -r requirements.txt
Usage
Initialize the OpenWeather class
To use the package, you'll need to initialize the OpenWeather class with your API key. You can get your API key by signing up at OpenWeatherMap or WeatherStack.
from openweather.weather import OpenWeather
# Initialize the OpenWeather class with your API key
api_key = "your_api_key_here"
weather_api = OpenWeather(api_key)
Get Current Weather Data
You can fetch current weather data by either providing a city name or geographical coordinates (latitude and longitude).
By City Name:
weather = weather_api.get_weather(city="London")
print(weather)
By Latitude and Longitude:
weather = weather_api.get_weather(lat=51.5074, lon=-0.1278) # Coordinates for London
print(weather)
Get Hourly Forecast (Next 24 Hours)
hourly_forecast = weather_api.get_hourly_forecast(city="Delhi")
print(hourly_forecast)
Get 7-Day Forecast
seven_day_forecast = weather_api.get_seven_day_forecast(city="London")
print(seven_day_forecast)
Plot Weather Data (Temperature)
weather_api.plot_weather(city="Delhi")
Caching
The package uses requests_cache to cache API responses for a specified duration. This reduces the number of requests made to the API and improves performance for subsequent calls. The default cache duration is 1 hour (3600 seconds), but you can modify it when initializing the class.
weather_api = OpenWeather(api_key="your_api_key_here", cache_duration=3600) # 1 hour cache duration
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
We welcome contributions! If you would like to contribute to this project, please fork the repository and submit a pull request. Make sure to follow the coding guidelines and write tests for any new functionality.
Contact
For any questions or support, feel free to open an issue on the GitHub repository or contact us directly at shrishkamboz@gmail.com.
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 openweather_wrapper-0.1.1.tar.gz.
File metadata
- Download URL: openweather_wrapper-0.1.1.tar.gz
- Upload date:
- Size: 11.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fa34371d8527846ed6cffec08fa8191fa70793af4442770333fb90d322693234
|
|
| MD5 |
60677edf95aafc3579a6ceee7209b6b2
|
|
| BLAKE2b-256 |
27d2bdcb597e1d155baebf54172a8dbb28e23755fea00c7b52408e700c33026c
|
File details
Details for the file openweather_wrapper-0.1.1-py3-none-any.whl.
File metadata
- Download URL: openweather_wrapper-0.1.1-py3-none-any.whl
- Upload date:
- Size: 10.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e5240911a6d2340f396605091bf0b6a26f5a15da9cc6f82087eb859c5478b5d2
|
|
| MD5 |
d8bf529f60e59346616004f65c7c0fbc
|
|
| BLAKE2b-256 |
50412eb23ae2d58f66dbd07d79588a5ba56060a0d533eaa9722ad84ed1c9a5b1
|