SDK for accessing to OpenWeatherAPI
Project description
OpenWeatherSDK
Introduction
SDK for accessing to OpenWeatherAPI and retrieving information about current weather conditions in a specified city. The SDK can operate in two modes: on-demand and polling. In on-demand mode (the default mode), API requests are made on user demand, while in the polling mode, there is regular polling of the API for weather updates in the saved (previously requested) cities.
Contents
Installation
pip install openweather_sdk
Prerequisites
To work with the SDK, you need to obtain an access token for OpenWeatherAPI. More information can be found on FAQ page ("Get started" section -> "How to get an API key").
Client initialization
The only required argument is the access token. Additionally, if you need to modify the behavior of the SDK, you can pass additional arguments.
Cache
Each client has its own cache, defined by the number of stored locations and the Time-To-Live (TTL) of the information. In polling mode, the TTL determines the API polling interval.
Additional arguments
By default, the SDK operates in on-demand mode, returns information in English, uses the metric system of measurements, has a cache size of 10 locations, and the information remains valid for 10 minutes. You can modify this mode by passing additional arguments during client initialization.
mode
- determines the operating mode of the SDK. In on-demand mode, the SDK
makes requests to the API only upon client requests. In polling mode, the SDK
regularly polls the API. Defaults: on-demand. Available options: on-demand, polling.
language
- determines the language for the output. Defaults: en. Available
options and more info see here.
units
- determines the units of measurements for the output. Defaults:
metric. Available options and more info see
here.
cache_size
- determines the number of stored locations in cache. Defaults: 10.
ttl
- determines the Time-To-Live of information in cache (in secs). Defaults:
600.
Usage example
>>> from openweather_sdk import Client
>>> c = Client(token=<YOUR_TOKEN>)
>>> c.health_check()
'The service is available'
>>> c.get_location_weather("Paris")
{'coord': {'lon': 2.32, 'lat': 48.859
}, 'weather': [
{'id': 300, 'main': 'Drizzle', 'description': 'light intensity drizzle', 'icon': '09d'
},
{'id': 500, 'main': 'Rain', 'description': 'light rain', 'icon': '10d'
}
], 'base': 'stations', 'main': {'temp': 7.29, 'feels_like': 5.98, 'temp_min': 6.3, 'temp_max': 7.84, 'pressure': 993, 'humidity': 94
}, 'visibility': 10000, 'wind': {'speed': 2.06, 'deg': 140
}, 'rain': {'1h': 0.21
}, 'clouds': {'all': 100
}, 'dt': 1710053464, 'sys': {'type': 2, 'id': 2012208, 'country': 'FR', 'sunrise': 1710051241, 'sunset': 1710092881
}, 'timezone': 3600, 'id': 6545270, 'name': 'Palais-Royal', 'cod': 200
}
>>> c.remove()
Errors
Description of possible errors can be found on FAQ page ("API errors" section).
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
Hashes for msklv_openweather_sdk-0.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44b755bbe4ede04d07da845c36b5a110a4f40d2d03e54ce42098b777f5737b35 |
|
MD5 | f67974c1edd426a481dafd8ae12780dc |
|
BLAKE2b-256 | 9f7a22ef6ccc188505b62f0e9f9163c6bc506dee3f8820bc2fc11a10ce8f9eab |
Hashes for msklv_openweather_sdk-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c4643883d19061b42ca28ce08768efc4b316f35e0ce2921c685295b29b115f1 |
|
MD5 | 8b97a126e8bc883e86f624cedf4e4f93 |
|
BLAKE2b-256 | b3a4b278d8a2755ecf2d3a7fe3de2d4d3571ea78b78784e3c7516b5cf542b5af |