OpenWeatherMap.API
4.0.1-pre
See the version list below for details.
dotnet add package OpenWeatherMap.API --version 4.0.1-pre
NuGet\Install-Package OpenWeatherMap.API -Version 4.0.1-pre
<PackageReference Include="OpenWeatherMap.API" Version="4.0.1-pre" />
<PackageVersion Include="OpenWeatherMap.API" Version="4.0.1-pre" />
<PackageReference Include="OpenWeatherMap.API" />
paket add OpenWeatherMap.API --version 4.0.1-pre
#r "nuget: OpenWeatherMap.API, 4.0.1-pre"
#:package OpenWeatherMap.API@4.0.1-pre
#addin nuget:?package=OpenWeatherMap.API&version=4.0.1-pre&prerelease
#tool nuget:?package=OpenWeatherMap.API&version=4.0.1-pre&prerelease
OpenWeatherMap.API
OpenWeatherMap API client for .NET
Download and Install OpenWeatherMap.API
This library is available on NuGet: https://www.nuget.org/packages/OpenWeatherMap.API Use the following command to install OpenWeatherMap.API using NuGet package manager console:
PM> Install-Package OpenWeatherMap.API
You can use this library in any .NET project which is compatible to .NET Standard 2.0 and higher.
Supported APIs
An API key is required for all API methods. Some API methods require a paid OpenWeatherMap subscription.
| Method | OpenWeatherMap API | Subscription |
|---|---|---|
GetCurrentWeatherAsync |
Current weather (data/2.5/weather) |
Free |
GetWeatherForecast5Async |
5 day / 3 hour forecast (data/2.5/forecast) |
Free |
GetWeatherForecast4Async |
Hourly forecast 4 days (data/2.5/forecast/hourly) |
Pro |
GetWeatherForecastDailyAsync |
Daily forecast 16 days (data/2.5/forecast/daily) |
Pro |
GetWeatherOneCallCurrentAsync |
One Call API 4.0 (data/4.0/onecall/current) |
One Call by Call |
GetWeatherOneCallMinutelyAsync |
One Call API 4.0 (data/4.0/onecall/timeline/1min) |
One Call by Call |
GetWeatherOneCall15MinutesAsync |
One Call API 4.0 (data/4.0/onecall/timeline/15min) |
One Call by Call |
GetWeatherOneCallHourlyAsync |
One Call API 4.0 (data/4.0/onecall/timeline/1h) |
One Call by Call |
GetWeatherOneCallDailyAsync |
One Call API 4.0 (data/4.0/onecall/timeline/1day) |
One Call by Call |
GetWeatherOneCallNextPageAsync, GetWeatherOneCallPreviousPageAsync |
One Call API 4.0 timeline pagination | One Call by Call |
GetWeatherOneCallAlertAsync |
One Call API 4.0 (data/4.0/onecall/alert/{id}) |
One Call by Call |
GetAirPollutionAsync, GetAirPollutionForecastAsync, GetAirPollutionHistoryAsync |
Air pollution (data/2.5/air_pollution) |
Free |
GetLocationsByNameAsync, GetLocationByZipCodeAsync, GetLocationsByCoordinatesAsync |
Geocoding API (geo/1.0) |
Free |
GetWeatherIconAsync |
Weather icons | Free |
API Usage
The following sections document basic use cases of this library. The following code excerpts can also be found in the sample applications.
Create weather service
OpenWeatherMapService is the main entry point of this library. Create an instance of OpenWeatherMapService or inject IOpenWeatherMapService using dependency injection techniques.
var openWeatherMapOptions = new OpenWeatherMapOptions
{
ApiKey = "<-INSERT-YOUR-API-KEY-HERE->",
UnitSystem = UnitSystem.Metric,
Language = "en",
};
IOpenWeatherMapService openWeatherMapService = new OpenWeatherMapService(logger, openWeatherMapOptions);
If you use Microsoft.Extensions.DependencyInjection, register IOpenWeatherMapService with AddOpenWeatherMap. The options can be bound to a configuration section (e.g. from appsettings.json) or configured in code:
serviceCollection.AddOpenWeatherMap(configuration.GetSection("OpenWeatherMap"));
{
"OpenWeatherMap": {
"ApiKey": "<-INSERT-YOUR-API-KEY-HERE->",
"UnitSystem": "metric",
"Language": "en"
}
}
Request current weather for GPS position
Call GetCurrentWeatherAsync with latitude and longitude to retrieve the current weather information for the given location. WeatherInfo is the model that contains all relevant information provided by OpenWeatherMap API.
var weatherInfo = await openWeatherMapService.GetCurrentWeatherAsync(latitude: 47.1823761d, longitude: 8.4611036d);
Console.WriteLine(
$"Current Weather Info:{Environment.NewLine}" +
$"Location: {weatherInfo.CityName}{Environment.NewLine}" +
$"Temperature: {weatherInfo.Main.Temperature}{Environment.NewLine}" +
$"Humidity: {weatherInfo.Main.Humidity}{Environment.NewLine}" +
$"Pressure: {weatherInfo.Main.Pressure}{Environment.NewLine}");
Request 5 day / 3 hour forecast
var weatherForecast = await openWeatherMapService.GetWeatherForecast5Async(latitude, longitude, count: 8);
foreach (var forecastItem in weatherForecast.Items)
{
Console.WriteLine($"{forecastItem.DateTime.ToLocalTime():g}: {forecastItem.Main.Temperature}");
}
Request weather data using One Call API 4.0
One Call API 4.0 provides current weather, a minute forecast for 1 hour, a 15 minutes forecast for 48 hours, an hourly timeline (history since 1979 and forecast for 48 hours), a daily timeline (history since 1979 and forecast for 1.5 years) and national weather alerts. It requires a "One Call by Call" subscription for One Call API 4.0; requests without this subscription fail with HTTP 401 (Unauthorized).
All One Call API 4.0 methods return a OneCallTimeline<T> with the weather records in property Data.
var currentTimeline = await openWeatherMapService.GetWeatherOneCallCurrentAsync(latitude, longitude);
var currentWeather = currentTimeline.Data.Single();
var dailyTimeline = await openWeatherMapService.GetWeatherOneCallDailyAsync(latitude, longitude);
foreach (var dailyForecast in dailyTimeline.Data)
{
Console.WriteLine($"{dailyForecast.DateTime:d}: {dailyForecast.Temperature.Min}/{dailyForecast.Temperature.Max}");
}
The timelines are paginated. Request the previous or next page of a timeline with GetWeatherOneCallPreviousPageAsync and GetWeatherOneCallNextPageAsync
(each page is billed as a separate API call). Historical data is requested by passing a start date:
// Hourly weather data of 2020-03-04, starting at 00:00 UTC
var hourlyTimeline = await openWeatherMapService.GetWeatherOneCallHourlyAsync(latitude, longitude, start: new DateTime(2020, 3, 4, 0, 0, 0, DateTimeKind.Utc));
var nextPage = await openWeatherMapService.GetWeatherOneCallNextPageAsync(hourlyTimeline); // null if there is no next page
Weather records reference weather alerts by ID. Use GetWeatherOneCallAlertAsync to get the details of an alert:
foreach (var alertId in currentWeather.Alerts)
{
var alertInfo = await openWeatherMapService.GetWeatherOneCallAlertAsync(alertId);
Console.WriteLine($"{alertInfo.SenderName}: {alertInfo.EventName}");
}
Find locations using the Geocoding API
// Coordinates by location name (city name, state code (US only), country code)
var locations = await openWeatherMapService.GetLocationsByNameAsync("Menznau,CH", limit: 1);
// Coordinates by zip/post code
var zipCodeLocation = await openWeatherMapService.GetLocationByZipCodeAsync("6122", "CH");
// Location names by coordinates (reverse geocoding)
var nearbyLocations = await openWeatherMapService.GetLocationsByCoordinatesAsync(latitude, longitude);
Request air pollution data
var airPollutionInfo = await openWeatherMapService.GetAirPollutionAsync(latitude, longitude);
var airPollutionForecast = await openWeatherMapService.GetAirPollutionForecastAsync(latitude, longitude);
var airPollutionHistory = await openWeatherMapService.GetAirPollutionHistoryAsync(latitude, longitude, start: DateTime.UtcNow.AddDays(-1), end: DateTime.UtcNow);
Migrating from 2.x to 4.0
OpenWeatherMap retired One Call API 2.5. Version 4.0 of this library migrates to One Call API 4.0 and contains the following breaking changes:
| 2.x | 4.0 |
|---|---|
GetWeatherOneCallAsync (CurrentWeather) |
GetWeatherOneCallCurrentAsync |
GetWeatherOneCallAsync (MinutelyForecasts) |
GetWeatherOneCallMinutelyAsync |
GetWeatherOneCallAsync (HourlyForecasts) |
GetWeatherOneCallHourlyAsync (or GetWeatherOneCall15MinutesAsync) |
GetWeatherOneCallAsync (DailyForecasts) |
GetWeatherOneCallDailyAsync |
GetWeatherOneCallAsync (Alerts) |
Alert IDs in Alerts of each weather record + GetWeatherOneCallAlertAsync |
GetWeatherOneCallHistoricAsync |
GetWeatherOneCallHourlyAsync with parameter start |
OneCallOptions, OneCallWeatherInfo |
Removed; each method returns a OneCallTimeline<T> |
HourlyWeatherForecast |
TimelineWeatherForecast |
AlertInfo.Description |
AlertInfo.Descriptions (one description per language) |
Further breaking changes:
UnitSystem.Standardreturns temperatures in Kelvin (as provided by OpenWeatherMap) instead of Celsius.IOpenWeatherMapServicehas new members. Custom implementations of this interface need to be extended.CurrentWeatherForecast.RainandCurrentWeatherForecast.Snoware nullable since they are only provided if available.
Contribution
Contributors welcome! If you find a bug or you want to propose a new feature, feel free to do so by opening a new issue on github.com.
License
This project is Copyright © 2026 Thomas Galliker. Free for non-commercial use. For commercial use please contact the author.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 is compatible. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.12)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.12)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.12)
- Microsoft.Extensions.Options (>= 10.0.12)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.12)
- System.Text.Json (>= 10.0.12)
- UnitsNet (>= 5.0.0 && < 6.0.0)
-
.NETStandard 2.1
- Microsoft.Extensions.Configuration.Abstractions (>= 10.0.12)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.12)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.12)
- Microsoft.Extensions.Options (>= 10.0.12)
- Microsoft.Extensions.Options.ConfigurationExtensions (>= 10.0.12)
- System.Text.Json (>= 10.0.12)
- UnitsNet (>= 5.0.0 && < 6.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on OpenWeatherMap.API:
| Repository | Stars |
|---|---|
|
immichFrame/ImmichFrame
|
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.8 | 124 | 10/7/2026 |
| 4.0.4-pre | 85 | 10/7/2026 |
| 4.0.1-pre | 85 | 10/7/2026 |
| 3.0.4 | 90 | 10/7/2026 |
| 3.0.1-pre | 83 | 10/6/2026 |
| 2.2.31 | 100 | 10/6/2026 |
| 2.2.29-pre | 92 | 10/6/2026 |
| 2.2.27-pre | 88 | 10/6/2026 |
| 2.2.14-pre | 136 | 6/3/2026 |
| 2.2.12-pre | 157 | 4/3/2026 |
| 2.2.10-pre | 130 | 4/2/2026 |
| 2.2.8-pre | 125 | 4/2/2026 |
| 2.1.4-pre | 1,892 | 10/18/2024 |
| 2.1.3-pre | 225 | 6/22/2024 |
| 2.1.2 | 14,251 | 5/14/2024 |
| 2.1.0-pre | 234 | 4/29/2024 |
| 2.0.59 | 606 | 4/23/2024 |
| 2.0.57-pre | 225 | 3/27/2024 |
| 2.0.53-pre | 223 | 3/11/2024 |
| 2.0.52-pre | 210 | 3/11/2024 |
4.0
- Migrate One Call API from 2.5 (retired by OpenWeatherMap) to 4.0; requires a "One Call by Call" subscription for One Call API 4.0
- Breaking: Remove GetWeatherOneCallAsync, GetWeatherOneCallHistoricAsync and OneCallOptions
- Add GetWeatherOneCallCurrentAsync, GetWeatherOneCallMinutelyAsync, GetWeatherOneCall15MinutesAsync, GetWeatherOneCallHourlyAsync and GetWeatherOneCallDailyAsync (returning OneCallTimeline<T>)
- Add GetWeatherOneCallNextPageAsync and GetWeatherOneCallPreviousPageAsync for timeline pagination
- Add GetWeatherOneCallAlertAsync; weather records reference alerts by ID (Alerts)
- Breaking: Rename HourlyWeatherForecast to TimelineWeatherForecast; AlertInfo follows the One Call API 4.0 format
- Add Geocoding API: GetLocationsByNameAsync, GetLocationByZipCodeAsync, GetLocationsByCoordinatesAsync
- Add GetAirPollutionForecastAsync and GetAirPollutionHistoryAsync
- Breaking: UnitSystem.Standard returns temperatures in Kelvin (was Celsius)
- Breaking: IOpenWeatherMapService has new members
- Fix DailyWeatherForecastItem.Wind which was not deserialized
- GetCurrentWeatherAsync validates latitude and longitude
2.2
- Maintenance updates
- Replace Newtonsoft.Json with System.Text.Json
- Change WeatherInfo.CityId from string to int
- Mark GetWeatherOneCallAsync and GetWeatherOneCallHistoricAsync as obsolete (One Call API 2.5 was retired by OpenWeatherMap)
2.1
- Extended the 16-day forecast model (DailyWeatherForecastItem) with missing properties
2.0
- Use unit types from dependency UnitsNet
1.2
- Major refactoring in wind direction data model
- Add multilingual support
1.0
- Initial release