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()
200
>>> 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.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac332754eb4f9ecc062ef34f9a3267db0cfc4baae1d0362d54dd8346f75dec7f |
|
MD5 | c26ddf7f4f6feb0afc4391964569be66 |
|
BLAKE2b-256 | b1d502f16fe7f48f1df484d6361bae61751ff6da403ca7045f6c55d166c772bc |
Hashes for msklv_openweather_sdk-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 23c965047d3cdbe14bb3e266a3c432ca7c5c6020a4efe31d8831c772ca8fb897 |
|
MD5 | 34ecaaea4182edba334c9353467d101d |
|
BLAKE2b-256 | c9485b11fdbbb94f11ab3613e07ffd8b94586516b50f8480f3e0ff8733090738 |