Python SDK for accessing OpenWeatherMap API
Project description
ApiClient Class Description
Installation:
pip install lagrunge82-test-sdk
Features:
- Retrieve weather information for specified cities.
- Support for two operation modes: "on-demand" and "polling".
Operation Modes:
- "On-demand":
- The SDK updates weather information only upon user request.
- Suitable for applications where weather information is not critical and does not require instant updates.
- "Polling":
- The SDK periodically requests new weather information for all stored locations to have zero latency response to user requests.
- Suitable for applications where quick access to up-to-date weather information is required.
Usage:
from lagrunge82_test_sdk.api_client import ApiClient
# Create an API client instance with your API key
api_client = ApiClient("YOUR_API_KEY", mode='on-demand')
# Get weather data for a city
weather_data = api_client.get_weather("London")
# Access weather information
print(f"Temperature: {weather_data['main']['temp']}")
Additional Features:
-
Data caching:
- The SDK caches received weather data to reduce the number of API requests.
- The default Time-to-Live (TTL) is 600 seconds (10 minutes).
- You can change the TTL if needed.
-
Geocoding:
- The SDK determines geographic coordinates by city name.
-
Error handling:
- The SDK handles errors that occur when interacting with the API.
- You can get error information and handle it according to your requirements.
# Get weather data for 5 cities
cities = ["London", "Paris", "Berlin", "New York", "Tokyo"]
for city in cities:
try:
weather_data = api_client.get_weather(city)
print(f"Weather data for {city}:")
print(weather_data)
except APIException as e:
print(f"Error getting weather data for {city}:")
print(e.message)
Other features:
- Multithreading:
- The SDK can perform requests to the OpenWeatherMap API in multithreaded mode, which can improve performance.
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 lagrunge82_test_sdk-0.3.tar.gz.
File metadata
- Download URL: lagrunge82_test_sdk-0.3.tar.gz
- Upload date:
- Size: 5.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.11.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e1258ce96ebb9a4f56057b922d241d497ea285785dbff4813676cd279dd9d7d3
|
|
| MD5 |
c552e177a2016e0aa211c1176d3e2746
|
|
| BLAKE2b-256 |
ebcf5ffd0bddfe2f185b02ff08244bf7119bb6440780dce8face3d58b9a3a394
|