Skip to main content

Library for fetching weather information from Finnish Meteorological Institute (FMI)

Project description

Test Last commit Latest version in GitHub Latest version in PyPi

Finnish Meteorological Institute Weather

Library for fetching weather information from Finnish Meteorological Institute (FMI).

If you want to know how FMI API works, you can check out their WFS Examples and Guidelines page.

For the current weather information, this library requests observations from the past 10 minutes using timestep 10. Based on my tests this gave pretty reliable results from different weather stations.

Originally, I created this for myself to get FMI weather data to Home Assistant. I am not a meteorologist so if you are more weather-savvy, feel free to contribute and provide improvements! 💖

FYI: I don't use Home Assistant or this library anymore, so I may not know if things are broken or need updating. However, I'm more than happy to maintain this library, so if you find a bug or a need to update a dependency, feel free to file an issue. Even better, file a pull request that fixes the issues! 😉 💖

How to use

Working example can be found in example.py.

Install

$ pip install fmi-weather-client 

Get weather and forecasts

You can get the weather using the following functions:

  • weather_by_place_name(place_name)
  • weather_by_coordinates(latitude, longitude)

Example:

import fmi_weather_client as fmi
from fmi_weather_client.errors import ClientError, ServerError

try:
    weather = fmi.weather_by_place_name("Jäppilä, Pieksämäki")
    if weather is not None:
        print(f"Temperature in {weather.place} is {weather.data.temperature}")
except ClientError as err:
    print(f"Client error with status {err.status_code}: {err.message}")
except ServerError as err:
    print(f"Server error with status {err.status_code}: {err.body}")

You can get the forecasts using the following functions:

  • forecast_by_place_name(place_name, [timestep_hours=24])
  • forecast_by_coordinates(latitude, longitude, [timestep_hours=24])

Example:

import fmi_weather_client as fmi
from fmi_weather_client.errors import ClientError, ServerError

try:
    forecast = fmi.forecast_by_coordinates(60.170998, 24.941325)
    for weather_data in forecast.forecasts:
        print(f"Temperature at {weather_data.time}: {weather_data.temperature}")
except ClientError as err:
    print(f"Client error with status {err.status_code}: {err.message}")
except ServerError as err:
    print(f"Server error with status {err.status_code}: {err.body}")

All functions have asynchronous versions available with async_ prefix.

Errors

ClientError

Happens if FMI service returns 400-499. This can happens for example if:

  • Provided coordinates are invalid
  • Provided place is not recognized
  • Weather data is not available

Error object contains status code and human-readable error message from FMI service.

ServerError

Happens if FMI service returns any other error.

Error object contains status code and raw response body from FMI service

Weather data

FMI provides the following commonly used information:

  • Temperature (°C)
  • Pressure (hPa)
  • Humidity (%)
  • Wind direction (°)
  • Wind speed (m/s)
  • Wind gust (m/s)
  • Dew point (°)
  • Cloud coverage (%)
  • Precipitation intensity (mm/h)
  • Symbol Documentation in Finnish
  • Feels like temperature (°C), calculated from weather data Documentation in Finnish

There are also other information available. Check models.py and FMI documentation for more info.

Development

Setup

Create and activate a virtual environment

$ python -m venv venv
$ source venv/bin/activate

Install required packages

$ make setup

Deactivate virtual environment when you are done

$ deactivate

Run tests

This will run unit tests and code quality checks

$ make test

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

fmi-weather-client-0.4.0.tar.gz (24.4 kB view details)

Uploaded Source

Built Distribution

fmi_weather_client-0.4.0-py3-none-any.whl (22.3 kB view details)

Uploaded Python 3

File details

Details for the file fmi-weather-client-0.4.0.tar.gz.

File metadata

  • Download URL: fmi-weather-client-0.4.0.tar.gz
  • Upload date:
  • Size: 24.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.20

File hashes

Hashes for fmi-weather-client-0.4.0.tar.gz
Algorithm Hash digest
SHA256 52d70d867a2b78ba559b1140f79dc8c6d9ac311dde142650c834fcf5299fc75f
MD5 d5f1bc3da0fa84a3314ef426c0a5726f
BLAKE2b-256 e3cdf13bead14e04d6b86d7a39c6cc0a07468aa3e1fdf7e2d89d3518a439a608

See more details on using hashes here.

File details

Details for the file fmi_weather_client-0.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fmi_weather_client-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 2c8b17e8695acadb446268c8544b86dea3ff82f2f9137655efcf3e6d9f0180cb
MD5 906436099d6b8e634023d36f67d6be41
BLAKE2b-256 a803d9eb2862c1f768a5fd56597594a22e79047b4295d31e2afe4f6938fa6d57

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page