Skip to main content

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

Example Package

Package Example

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openweather_wrapper-0.1.0.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

openweather_wrapper-0.1.0-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file openweather_wrapper-0.1.0.tar.gz.

File metadata

  • Download URL: openweather_wrapper-0.1.0.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.2

File hashes

Hashes for openweather_wrapper-0.1.0.tar.gz
Algorithm Hash digest
SHA256 27e3d57c646451535bc167b85d2160871b48db6b36767d4ac63f8a09540a9302
MD5 bfcf53b0051ebbd12e39eb923bb4595f
BLAKE2b-256 e00c72192aa9bffa9760c9bd0ec5d23f3a775b4c5fb544cb37d659640ad8cd7e

See more details on using hashes here.

File details

Details for the file openweather_wrapper-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for openweather_wrapper-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ade789f36333f48f1dc3a5b8da6b30fac2bc54df93f7b9752ca3c652178db928
MD5 44e2e6ca2cfb131dde1af192a4b615a3
BLAKE2b-256 e66b7f59c773a328dcdf13d6da33f97a9af3b2775ab25cc0f147afc0a7257281

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page