pyipma
Asynchronous Python library to retrieve weather information from Instituto Português do Mar e Atmosfera (IPMA).
Supports weather observations, forecasts at 1-, 3-, and 24-hour intervals, three-day sea forecasts, weather warnings, UV risk, and fire risk (RCM). Locations and nearby stations are selected from geographic coordinates.
Installation
Requires Python 3.14 or newer. Runtime dependencies are aiohttp>=3.14.5 and
geopy>=2.5.0, installed automatically with the package:
python -m pip install pyipma
Example
Pass coordinates to Location.get() positionally as latitude, longitude.
Create and close the aiohttp.ClientSession in your application.
import asyncio
import aiohttp
from pyipma.api import IPMA_API
from pyipma.location import Location
async def main() -> None:
async with aiohttp.ClientSession() as session:
api = IPMA_API(session)
location = await Location.get(api, 40.6517, -8.6573, sea_stations=True)
print(f"Forecast for {location.name}")
print(f"Nearest station is {location.station}")
print(f"Nearest sea station is {location.sea_station_name}")
obs = await location.observation(api)
if obs is not None:
print(f"Latest observation: {obs}")
forecasts = await location.forecast(api, period=24)
for forecast in forecasts:
print(f"Forecast for {forecast.forecast_date}: {forecast}")
sea_forecasts = await location.sea_forecast(api)
for sea_forecast in sea_forecasts:
print(f"Sea forecast for {sea_forecast.forecastDate}: {sea_forecast}")
print("Weather warnings:", await location.warnings(api))
print("UV risk:", await location.uv_risk(api))
print("Fire risk today:", await location.fire_risk(api, day=0))
asyncio.run(main())
location.forecast(api, period=...) accepts 1, 3, or 24 (the default),
and returns forecasts sorted by date. The first daily forecast can be for today;
use forecast_date to identify the day. location.sea_forecast(api) returns a
date-sorted list for today and the next two days and requires
sea_stations=True when creating the location.
The location methods try up to ten nearby locations or stations for weather
forecasts, observations, and sea forecasts. If retrieval fails, forecast methods
return an empty list; observation and risk methods return None. Warnings return
a list (which can be empty), or None if retrieval fails or no warning area is
available. Check these results before indexing or accessing model properties.
IPMA_API uses a ten-second request timeout by default. Its timeout argument
accepts seconds, an aiohttp.ClientTimeout, or None to use the session's
timeout. Low-level request failures raise pyipma.IPMAException.
Forecast data
Forecasts expose precipitation_intensity (the API's idIntensidadePrecipita
class code), uv_index, and wind_speed_class. To resolve an intensity code
to an English or Portuguese description, use
await Precipitation_Classes(api).get(forecast.precipitation_intensity) from
pyipma.auxiliar when the code is not None. Class definitions are listed in
the IPMA API documentation.
Coastal entries in Forecast also expose sea_temperature, wave_direction, wave_height,
swell_height, swell_period, and peak_period when returned by IPMA. These
properties are None for periods or locations without marine data. The original
API field names remain available on the forecast object. The separate
SeaForecast model returned by location.sea_forecast() exposes daily minimum
and maximum sea temperatures, wave heights, and swell periods, plus wave direction.
Forecast humidity, UV index, and feels-like temperature are numeric values;
missing values (-99) become None, and zero remains valid. Fire-risk objects
expose forecast_date and run_date as dates and update_date as a datetime.
Auxiliary parsers and SeaForecasts also retain the API's owner and country
metadata after retrieval.
Type checking
The library ships inline type annotations and a py.typed marker for downstream
type checkers. Parsed models and parser methods expose concrete return types,
including None for unavailable values. The low-level IPMA_API.retrieve()
method returns dynamic JSON or text; use the parsers for typed results.
Install development dependencies and run the strict type checks:
venv/bin/python -m pip install -e ".[dev]"
venv/bin/python -m mypy
These checks cover the library and consumer examples in tests/typing and run
in CI alongside the live API tests.
Running tests
Install the test dependencies in a virtual environment, then run pytest:
python3.14 -m venv venv
venv/bin/python -m pip install -e ".[test]"
venv/bin/python -m pytest
The suite includes static parser and error-handling tests as well as tests that call IPMA's live API and require internet access. Endpoint failures, response schema changes, and parsing errors fail the suite so upstream changes are visible. Live field-coverage tests also fail when supported endpoints add properties that the library does not yet model. These checks cover the endpoints used by pyipma; they do not discover unrelated IPMA services.
The Live API compatibility GitHub Actions workflow runs this suite daily at
08:23 UTC and can also be started from the Actions tab using Run workflow.
It checks the current library against live IPMA responses, including field
coverage and parsing compatibility. API outages also fail the run. Each run
uploads a JUnit test report as the live-api-test-results artifact for diagnosis.
Scheduled runs use the repository's default branch.
Changelog
Unreleased
- Normalize observation measurements, including missing wind speed (
-99), while preserving zero and valid99values. - Handle missing observation fields and unavailable or unknown wind directions; keep station observations sorted chronologically.
- Preserve zero and normalize missing numeric values in sea forecasts, UV risk, fire risk, and forecast class codes.
- Return unavailable descriptions for missing UV/fire risk and normalize string location IDs in sea and UV forecasts.
- Filter forecasts using UTC and validate forecast periods and fire-risk days explicitly.
- Resolve auxiliary classes by ID and sort cached locations for each coordinate query.
- Sort warnings chronologically and parse dates only for the requested area.
3.1.0 — 2026-11-21
Compatibility: Python 3.14 or newer is now required. Users on Python 3.13 or older should stay on pyipma 3.0.10 until they upgrade Python.
- Require Python 3.14+, refresh runtime/build/development dependency minimums, and align CI and mypy with Python 3.14.
- Expose precipitation intensity, UV index, wind speed class, and coastal fields on forecasts.
- Normalize numeric forecast values, preserve zero, and treat missing values as
None. - Expose fire-risk forecast, run, and update dates, and retain API owner/country metadata.
- Ship inline type annotations and
py.typed, with strict mypy checks for the library and consumer examples. - Expand live API parsing and field-coverage checks across mainland Portugal, Madeira, and the Azores.
- Add the daily Live API compatibility workflow and downloadable JUnit reports.
Releases
- 3.0.10 - Update aiohttp support and HTTP/JSON error handling, fix sea forecasts, and modernize packaging and CI
- 3.0.9 - Adjust forecast window for 24 hours periods
- 3.0.8 - Adds Weather Warnings
- 3.0.7 - Adds UV Index (@tokenize74)
- 3.0.6 - Bug Fixes
- 3.0.3 - Adds RCM (Fire Risk)
- 3.0.2 - Changes to fully support Home Assistant integration
- 3.0.0 - Backend fully rewritten, but keeping backward compatibility at interface level
- 2.1.5 - Better logging and code formated with black
- 2.1.0 - Sea Forecast
- 2.0.5 - Look for previous observations when no temperature/humidity available
- 2.0.4 - Ignore Observation stations with temperature/humidity -99
- 2.0.3 - Searches next closest station when offline
- 2.0.2 - Adds Station Lat/Lon
- 2.0.1 - fixes
- 2.0.0 - Major refactor
- 1.2.1 - Fix pip
- 1.2.0 - Wind direction corrected
- 1.1.6 - Interpret -99 and unavailable
- 1.1.5 - Cache values
- 1.1.4 - New API
- ...
Credits
Values are obtained from IPMA.
Contributors
@abmantis @joaocps
Copyright
(C) 2018,2019,2020 Diogo Gomes diogogomes@gmail.com
Metadata
Release files for pyipma 3.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyipma-3.1.0.tar.gz | 33.9 kB | Without provenance | Details for pyipma-3.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyipma-3.1.0-py3-none-any.whl | Python 3 | none | any | Details for pyipma-3.1.0-py3-none-any.whl |
Total release size: 56.7 kB
Release files / pyipma-3.1.0.tar.gz
| Download URL | pyipma-3.1.0.tar.gz |
|---|---|
| Size | 33.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5eea0f2c322ab2b521314c55d07bd56a3b1b29dd9d278c57fd149ac2b7412354
|
|
BLAKE2b-256 checksum How to use checksums |
5b4ac250a48802a182c85d51e110adf7f792d9dcf778dbcc5dac2371489e4fbf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Release files / pyipma-3.1.0-py3-none-any.whl
| Download URL | pyipma-3.1.0-py3-none-any.whl |
|---|---|
| Size | 22.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
818b78bb0c56b1a6d5592b3074a4a9870c64974bd7eb74d8d614d5f9863afc27
|
|
BLAKE2b-256 checksum How to use checksums |
4a402bde6389d6760b5d124131cd5231609497c9aa438f3009c8870575ca287c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Security for pyipma 3.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.