SDK for accessing weather data
Project description
WeatherSDK
WeatherSDK is a Python package that allows you to retrieve weather information for different cities using the OpenWeatherMap API. It provides two modes of operation: on-demand and polling.
Installation
You can install the WeatherSDK package using pip:
pip install weather_sdk
Usage
To use WeatherSDK in your Python code, follow these steps:
-
Import the WeatherSDK class:
from weathersdk import WeatherSDK
-
To use the WeatherSDK package, you need to get an API key from OpenWeatherMap. Visit the OpenWeatherMap website and sign up to get your API key.
-
Initialize an instance of the WeatherSDK class with your API key and the desired mode:
api_key = "" mode = 'on_demand' or 'polling' sdk = WeatherSDK(api_key=api_key, mode=mode)
-
Retrieve weather data for a specific city using the 'get_weather' method:
city = 'New York' weather_data = sdk.get_weather(city=city) print(weather_data)
-
Delete an SDK instance by removing its key from storage using the 'delete' method.
sdk = WeatherSDK(api_key=api_key, mode=mode) sdk.delete()
Modes of Operation
WeatherSDK supports two modes of operation:
On-demand Mode
In on-demand mode, the SDK retrieves weather information for a specific city only when requested. It caches the data for subsequent requests within a 10-minute timeframe.
sdk = WeatherSDK(api_key=api_key, mode="on_demand")
weather_data = sdk.get_weather(city=city)
Polling Mode
In polling mode, the SDK automatically updates the weather information for all saved cities at regular intervals. The data for each city are refreshed every 10 minutes. In this mode, the city name does not need to be transmitted, since the data are taken from existing data.
sdk = WeatherSDK(api_key=api_key, mode="polling")
weather_data = sdk.get_weather()
General example
from weathersdk import WeatherSDK
api_key = "<your-api-key>"
city = 'London'
mode_1 = 'on_demand'
sdk = WeatherSDK(api_key=api_key, mode=mode_1)
weather_data_london = sdk.get_weather(city=city)
print(weather_data_london)
'''
{
'weather': {
'main': 'Clouds',
'description':
'overcast clouds'
},
'temperature': {
'temp': 282.46,
'feels_like': 280.78
},
'visibility': 10000,
'wind': {
'speed': 3.09
},
'datetime': 1710019683,
'sys': {
'sunrise': 1709965652,
'sunset': 1710006877
},
'timezone': 0,
'name': 'London',
}
'''
mode_2 = 'polling'
sdk_2 = WeatherSDK(api_key=api_key, mode=mode_2)
weather_data_all_city = sdk_2.get_weather()
print(weather_data_all_city)
'''
{
'London': {
'data': {
'weather': {
'main': 'Clouds',
'description':
'overcast clouds'},
'temperature': {
'temp': 282.46,
'feels_like': 280.78
},
'visibility': 10000,
'wind': {
'speed': 3.09
},
'datetime': 1710019683,
'sys': {
'sunrise': 1709965652,
'sunset': 1710006877
},
'timezone': 0,
'name': 'London',
}
}
}
'''
sdk.delete()
sdk_2.delete()
Documentation
For detailed documentation, including information about methods and parameters, refer to the WeatherSDK Documentation.
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
File details
Details for the file weather_sdk-1.0.0.tar.gz.
File metadata
- Download URL: weather_sdk-1.0.0.tar.gz
- Upload date:
- Size: 2.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
93c3422ebd92748103572e2f5793adc2be9abaf6b421376fb2b4234bc19169a9
|
|
| MD5 |
629c62709a932ef23cfb590737858238
|
|
| BLAKE2b-256 |
a98c202fe03c8318a6f6be2ad21fd682bda045f4aa797093acb911710936d5ff
|