Retrieve weather data from Yr (by the Norwegian Meteorogical Institute) easily.
Project description
yr-weather
Retrieve weather data from Yr (by the Norwegian Meteorogical Institute) easily.
yr-weather
is an API wrapper for some of the products from Yr's API.
Available on PyPI:
Supported products are:
- Locationforecast (v2.0)
- Radar (v2.0)
- Textforecast (v2.0)
Installing
To use yr-weather
, simply install it using pip
like so (Windows):
pip install yr-weather
For Linux/macOS, run:
python3 -m pip install yr-weather
Getting started
To get started with Locationforecast, instantiate a Locationforecast
class and use the provided functions.
A simple example follows (more features are available).
import yr_weather
# Replace with your own User-Agent. See MET API Terms of Service for correct User-Agents.
headers = {
"User-Agent": "Your User-Agent"
}
yr_client = yr_weather.Locationforecast(headers=headers)
# Get air temperature in Oslo, Norway
oslo_temp = yr_client.get_air_temperature(59.91, 10.75)
# Get full weather data for Oslo, Norway
weather_data = yr_client.get_forecast(59.91, 10.75)
print(oslo_temp)
# Output: 8.0
# Get data from a typed dict
print(weather_data["properties"]["timeseries"][0]["data"]["instant"]["details"])
# Example output:
# {
# "air_pressure_at_sea_level": 1034.7,
# "air_temperature": -1.5,
# "air_temperature_percentile_10": -2.5,
# "air_temperature_percentile_90": -0.9,
# "cloud_area_fraction": 99.9,
# "cloud_area_fraction_high": 90.9,
# "cloud_area_fraction_low": 62.9,
# "cloud_area_fraction_medium": 95.7,
# "dew_point_temperature": -4.4,
# "fog_area_fraction": 0.0,
# "relative_humidity": 82.1,
# "ultraviolet_index_clear_sky": 0.0,
# "wind_from_direction": 11.3,
# "wind_speed": 0.2,
# "wind_speed_of_gust": 0.7,
# "wind_speed_percentile_10": 0.3,
# "wind_speed_percentile_90": 0.7
# }
All functions and classes are documented with docstrings. Further documentation will be made at a later point in time.
Caching
By default, the library makes a cache file named yr_cache.sqlite
in the working directory.
To disable caching, set use_cache
to False
like so:
yr_weather.Locationforecast(headers=headers, use_cache=False)
MET's Terms of Service encourage using caching, to avoid extra load on the network. Therefore, this feature is not recommended.
Future objectives (TODOs)
- Add Read the Docs documentation
- Add further features from MET's API
- Improve support for earlier Python versions
License
This project is licensed under the GNU General Public License v3.
Disclaimer
yr-weather
is not associated with yr.no or the Norwegian Meteorological Institute (MET).
Any usage of the APIs provided by MET must follow their API Terms of Service.
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
Built Distribution
Hashes for yr_weather-0.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05aa2b0e02f6d16d135b35ca17c29c8504763d0b77b90d4170233256ae0bf6eb |
|
MD5 | 512ec036e94092702dabe809ebf941bc |
|
BLAKE2b-256 | 4a349b0df869d56d837936df4fa15e9f37c903054e2e67df449b9330514f5f09 |