Skip to main content

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 openweather_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


Download files

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

Source Distribution

lagrunge82_test_sdk-0.2.tar.gz (5.7 kB view details)

Uploaded Source

File details

Details for the file lagrunge82_test_sdk-0.2.tar.gz.

File metadata

  • Download URL: lagrunge82_test_sdk-0.2.tar.gz
  • Upload date:
  • Size: 5.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.11.4

File hashes

Hashes for lagrunge82_test_sdk-0.2.tar.gz
Algorithm Hash digest
SHA256 96aa282bcdf17631c021e13426a49c44cf6ecc51a9773f1582e12cc5252c0254
MD5 ba300a66ca07536c2467326c4b228f9c
BLAKE2b-256 3e9a6a609dc2c180a00e7f93867df785ee09b1b6b4909cd96305a5800128f2c1

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