Skip to main content

Python library to fetch weather data from multiple providers

Project description

akvo-weather-info

A Python library to fetch weather data from multiple providers (OpenWeatherMap, WeatherAPI.com).

Installation

pip install akvo-weather-info

For development:

pip install -e .

Configuration

Create a .env file in your project root with API keys:

OPENWEATHER=your_openweathermap_api_key
WEATHERAPI=your_weatherapi_api_key

Get API keys from:

Library Usage

Basic Import

from weather.services import OpenWeatherMapService, WeatherAPIService

# Using OpenWeatherMap
owm = OpenWeatherMapService()
current = owm.get_current("Jakarta")
print(f"Temperature: {current.temperature}C")
print(f"Condition: {current.description}")

# Using WeatherAPI.com
wa = WeatherAPIService()
current = wa.get_current("London")
print(f"Temperature: {current.temperature}C")

Get Forecast

from weather.services import OpenWeatherMapService

service = OpenWeatherMapService()

# Hourly forecast
hourly = service.get_forecast_hourly("Tokyo", hours=24)
for forecast in hourly:
    print(f"{forecast.forecast_time}: {forecast.temperature}C")

# Daily forecast
daily = service.get_forecast_daily("New York", days=5)
for forecast in daily:
    print(f"{forecast.forecast_time.date()}: {forecast.temperature}C")

Get Raw API Response

from weather.services import WeatherAPIService

service = WeatherAPIService()

# Raw response as dict
raw = service.get_current_raw("Jakarta")
print(raw["current"]["temp_c"])
print(raw["current"]["condition"]["text"])

# Raw forecast
raw_forecast = service.get_forecast_raw("Jakarta")
print(raw_forecast["forecast"]["forecastday"])

Data Models

from weather.models import WeatherData, Forecast

# WeatherData fields
weather.location      # str: "Jakarta, ID"
weather.temperature   # float: temperature in Celsius
weather.feels_like    # float: feels like temperature
weather.humidity      # int: humidity percentage
weather.description   # str: weather description
weather.wind_speed    # float: wind speed in m/s
weather.timestamp     # datetime: data timestamp

# Convert to dict
data_dict = weather.to_dict()

Formatters

from weather.services import OpenWeatherMapService
from weather.formatters import format_json, format_text

service = OpenWeatherMapService()
current = service.get_current("Jakarta")

# Format as JSON string
json_output = format_json(current)

# Format as readable text
text_output = format_text(current)

CLI Usage

python -m weather --service=<SERVICE> --location=<LOCATION> [--output=<FORMAT>] [--forecast=<TYPE>] [--raw]

Arguments

Argument Required Values Description
--service Yes owm, wa Weather service (owm = OpenWeatherMap, wa = WeatherAPI.com)
--location Yes string Location name (e.g., "Jakarta", "London,UK")
--output No text, json Output format (default: text)
--forecast No hour, day Forecast type. If omitted, shows current weather
--raw No flag Show raw API response without field mapping

CLI Examples

# Current weather
python -m weather --service=owm --location="Jakarta"

# JSON output
python -m weather --service=wa --location="London" --output=json

# Hourly forecast
python -m weather --service=wa --location="Tokyo" --forecast=hour

# Daily forecast
python -m weather --service=owm --location="New York" --forecast=day

# Raw API response
python -m weather --service=owm --location="Jakarta" --raw --output=json

Project Structure

weather/
├── __init__.py
├── __main__.py          # CLI entry point
├── cli.py               # Argument parsing
├── config.py            # API key management
├── models.py            # Data models (WeatherData, Forecast)
├── services/
│   ├── base.py          # Abstract base class
│   ├── openweathermap.py
│   └── weatherapi.py
└── formatters/
    ├── json_formatter.py
    ├── text_formatter.py
    └── raw_formatter.py

Requirements

  • Python >= 3.10
  • httpx
  • python-dotenv

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

akvo_weather_info-0.2.0.tar.gz (20.1 kB view details)

Uploaded Source

Built Distribution

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

akvo_weather_info-0.2.0-py3-none-any.whl (23.7 kB view details)

Uploaded Python 3

File details

Details for the file akvo_weather_info-0.2.0.tar.gz.

File metadata

  • Download URL: akvo_weather_info-0.2.0.tar.gz
  • Upload date:
  • Size: 20.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for akvo_weather_info-0.2.0.tar.gz
Algorithm Hash digest
SHA256 3149f2059b17f8add7fc0dcd25f73c21e1947691e9699f0642b346e90c5e4349
MD5 30ae91edd318f1d6a2da0785c5a4dcb2
BLAKE2b-256 804ada6b43ab42260ddc7b13931276bb37584ff963addfcdd0f98349101b21f0

See more details on using hashes here.

Provenance

The following attestation bundles were made for akvo_weather_info-0.2.0.tar.gz:

Publisher: workflow.yml on akvo/weather-info

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file akvo_weather_info-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for akvo_weather_info-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 0db0e681cad8c608170c705c88a757aec3688ed65d513ab8426e10e84b961609
MD5 76597dc2b6e489ef3815d870bbd38730
BLAKE2b-256 b88deee5235462ab0a5090f3001aaf97c48cabddcb9b118e8ea264a0c5f4ce75

See more details on using hashes here.

Provenance

The following attestation bundles were made for akvo_weather_info-0.2.0-py3-none-any.whl:

Publisher: workflow.yml on akvo/weather-info

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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