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.
- 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
.
pip install openweather-wrapper
git clone https://github.com/yourusername/openweather-wrapper.git
cd openweather-wrapper
pip install .
- Python 3.6 or higher
- requests
- requests_cache
- matplotlib
You can install the required dependencies using pip:
pip install -r requirements.txt
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)
You can fetch current weather data by either providing a city name or geographical coordinates (latitude and longitude).
weather = weather_api.get_weather(city="London")
print(weather)
weather = weather_api.get_weather(lat=51.5074, lon=-0.1278) # Coordinates for London
print(weather)
hourly_forecast = weather_api.get_hourly_forecast(city="Delhi")
print(hourly_forecast)
seven_day_forecast = weather_api.get_seven_day_forecast(city="London")
print(seven_day_forecast)
weather_api.plot_weather(city="Delhi")
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
This project is licensed under the MIT License - see the LICENSE file for details.
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.
For any questions or support, feel free to open an issue on the GitHub repository or contact us directly at [email protected].