Skip to main content

Python SDK for OpenWeatherMap API

Project description

OpenWeather SDK

A lightweight and developer-friendly Python SDK for interacting with the OpenWeather API.

This library provides a clean interface for retrieving:

  • Geographic coordinates for cities
  • Current weather conditions
  • 5‑day weather forecasts

The SDK handles authentication, parameter injection, retries, and error handling internally so developers can focus on building features.


Features

  • Simple and intuitive API
  • Automatic injection of required OpenWeather parameters
  • Built-in HTTP retry strategy
  • Custom exception handling
  • Typed response models using dataclasses
  • Fully tested with pytest
  • ~95% test coverage

Installation

Install from source

Clone the repository and install in editable mode:

pip install -e .

Or using uv:

uv pip install -e .

Quick Start

from openweather_sdk import OpenWeatherClient

client = OpenWeatherClient(api_key="YOUR_API_KEY")

Get City Coordinates

coords = client.get_coordinates("São Paulo", country_code="BR")

print(coords.lat)
print(coords.lon)

Example return:

Coordinates(lat=-23.55, lon=-46.63)

Get Current Weather

from openweather_sdk import Coordinates

coords = Coordinates(lat=-23.55, lon=-46.63)

weather = client.get_current_weather(coords)

print(weather.temperature)
print(weather.description)
print(weather.icon)

Example return:

WeatherData(
    temperature=25.0,
    feels_like=27.0,
    min_temperature=24.0,
    max_temperature=26.0,
    humidity=70,
    pressure=1013,
    description="scattered clouds",
    icon="03d"
)

Get Weather Forecast

forecast = client.get_forecast(coords)

for item in forecast:
    print(item.dt_txt, item.weather.temperature)

Returns forecast data at 3‑hour intervals for the next 5 days.


Error Handling

The SDK raises custom exceptions for common API errors.

Exception Description


AuthenticationError Invalid API key NotFoundError Resource not found RateLimitError API rate limit exceeded OpenWeatherError Generic API error

Example:

from openweather_sdk.exceptions import AuthenticationError

try:
    client.get_current_weather(coords)
except AuthenticationError:
    print("Invalid API key")

Running Tests

The project uses pytest.

Run tests:

pytest

Run tests with coverage:

pytest --cov=openweather_sdk --cov-report=term-missing

Project Structure

open_weather_sdk/
│
├── src/
│   └── openweather_sdk/
│       ├── client.py
│       ├── http.py
│       ├── models.py
│       ├── exceptions.py
│       └── __init__.py
│
├── tests/
│   ├── conftest.py
│   ├── test_client.py
│   └── test_http_client.py
│
├── pyproject.toml
└── README.md

Requirements

  • Python 3.10+
  • requests

Development dependencies:

  • pytest
  • pytest-cov

Contributing

Contributions are welcome!

If you would like to contribute:

  1. Fork the repository
  2. Create a feature branch
  3. Write tests for your changes
  4. Open a Pull Request

License

MIT License

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

weather_sdk_challenge-0.1.0.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

weather_sdk_challenge-0.1.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file weather_sdk_challenge-0.1.0.tar.gz.

File metadata

  • Download URL: weather_sdk_challenge-0.1.0.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.11

File hashes

Hashes for weather_sdk_challenge-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a572fa155ad588ae0700d47061efb0f2a0faecdd601234f73b9a439d0b940764
MD5 a49c7601480e9ac8460c490140af7c16
BLAKE2b-256 0035ce79f4241abc08805c6ee1cb93eaef271b7e95587130fb4b464cbad81b52

See more details on using hashes here.

File details

Details for the file weather_sdk_challenge-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for weather_sdk_challenge-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ad6d51fe086e9fe0b46ea95497a178d100ddfbc10a6a4842c4cbfd475af580c4
MD5 69453d48bcd0693dad90e3f165221e2d
BLAKE2b-256 94572f90097a7b0afcf839327a505b471a7c44ad467224c503ee54833f09438d

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