Skip to main content

Async Python client for the Servicio Meteorológico Nacional Argentina (SMN) API

Project description

py-ha-smn

Async Python client for the Servicio Meteorológico Nacional Argentina (SMN) API.

This library is designed for use with Home Assistant.

Installation

pip install py-ha-smn

Usage

import aiohttp
from smn_argentina_api import SMNApiClient, SMNTokenManager

async def main():
    async with aiohttp.ClientSession() as session:
        # Create token manager and API client
        token_manager = SMNTokenManager(session)
        client = SMNApiClient(session, token_manager)

        # Get location ID from coordinates
        location = await client.async_get_location(-34.6037, -58.3816)
        location_id = str(location.get("id"))

        # Fetch current weather
        weather = await client.async_get_current_weather(location_id)
        print(f"Temperature: {weather.get('temperature')}°C")

        # Fetch forecast
        forecast = await client.async_get_forecast(location_id)
        print(f"Forecast days: {len(forecast.get('forecast', []))}")

        # Fetch alerts
        alerts = await client.async_get_alerts(location_id)
        print(f"Warnings: {len(alerts.get('warnings', []))}")

if __name__ == "__main__":
    import asyncio
    asyncio.run(main())

API Methods

SMNApiClient

  • async_get_location(latitude, longitude) - Get location ID from coordinates
  • async_get_current_weather(location_id) - Fetch current weather data
  • async_get_forecast(location_id) - Fetch weather forecast
  • async_get_alerts(location_id) - Fetch weather alerts
  • async_get_shortterm_alerts(location_id) - Fetch short-term severe weather alerts
  • async_get_heat_warnings(area_id) - Fetch heat warnings

SMNTokenManager

Handles JWT token authentication with the SMN API. Automatically refreshes tokens before expiration.

Exceptions

  • SMNError - Base exception for all SMN API errors
  • SMNConnectionError - Connection to SMN API failed
  • SMNAuthenticationError - Authentication with SMN API failed
  • SMNTokenError - Token fetching or parsing failed

License

Apache License 2.0

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

py_ha_smn-1.0.0.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

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

py_ha_smn-1.0.0-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file py_ha_smn-1.0.0.tar.gz.

File metadata

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

File hashes

Hashes for py_ha_smn-1.0.0.tar.gz
Algorithm Hash digest
SHA256 1e6b1671b613472a1510b0eee5f0321f242d45c8e831d7757b107e3c4d3ed8ec
MD5 f1bae8b6672c737ab0c7abccdfd9be40
BLAKE2b-256 840115c81bfd330419cf229e332e13308fa7a3c36046af61c00e1df4de352b7d

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_ha_smn-1.0.0.tar.gz:

Publisher: workflow.yaml on catastrophicode/py-ha-smn

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

File details

Details for the file py_ha_smn-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: py_ha_smn-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for py_ha_smn-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f6616e26c59e02310951c44af33668e545188410722414a0cda09d2fb07359c2
MD5 89035fe779448422b978b4a7fad38b98
BLAKE2b-256 9f55e762b73a0523e36c76784f0c01a462445c4c9ba544d185e1e2a433cbd847

See more details on using hashes here.

Provenance

The following attestation bundles were made for py_ha_smn-1.0.0-py3-none-any.whl:

Publisher: workflow.yaml on catastrophicode/py-ha-smn

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