OpenWeatherMap.API
3.0.4
See the version list below for details.
dotnet add package OpenWeatherMap.API --version 3.0.4
NuGet\Install-Package OpenWeatherMap.API -Version 3.0.4
<PackageReference Include="OpenWeatherMap.API" Version="3.0.4" />
<PackageVersion Include="OpenWeatherMap.API" Version="3.0.4" />
<PackageReference Include="OpenWeatherMap.API" />
paket add OpenWeatherMap.API --version 3.0.4
#r "nuget: OpenWeatherMap.API, 3.0.4"
#:package OpenWeatherMap.API@3.0.4
#addin nuget:?package=OpenWeatherMap.API&version=3.0.4
#tool nuget:?package=OpenWeatherMap.API&version=3.0.4
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 |
GetWeatherOneCallAsync |
One Call API 3.0 (data/3.0/onecall) |
One Call by Call |
GetWeatherOneCallTimeMachineAsync |
One Call API 3.0 (data/3.0/onecall/timemachine) |
One Call by Call |
GetWeatherOneCallDaySummaryAsync |
One Call API 3.0 (data/3.0/onecall/day_summary) |
One Call by Call |
GetWeatherOneCallOverviewAsync |
One Call API 3.0 (data/3.0/onecall/overview) |
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 3.0
One Call API 3.0 provides current weather, minutely forecast for 1 hour, hourly forecast for 48 hours, daily forecast for 8 days and government weather alerts in one request. It requires a "One Call by Call" subscription; requests without this subscription fail with HTTP 401 (Unauthorized).
var oneCallWeatherInfo = await openWeatherMapService.GetWeatherOneCallAsync(latitude, longitude, new OneCallOptions
{
IncludeMinutelyForecasts = false,
IncludeAlerts = false,
});
foreach (var dailyForecast in oneCallWeatherInfo.DailyForecasts)
{
Console.WriteLine($"{dailyForecast.DateTime:d}: {dailyForecast.Temperature.Min}/{dailyForecast.Temperature.Max}, {dailyForecast.Summary}");
}
// Weather data for any timestamp from 1979-01-01 up to 4 days ahead
var timeMachineInfo = await openWeatherMapService.GetWeatherOneCallTimeMachineAsync(latitude, longitude, new DateTime(2020, 3, 4, 12, 0, 0, DateTimeKind.Utc));
// Aggregated weather data for a date from 1979-01-02 up to 1.5 years ahead
var daySummary = await openWeatherMapService.GetWeatherOneCallDaySummaryAsync(latitude, longitude, new DateTime(2020, 3, 4));
// Human-readable weather summary for today or tomorrow
var weatherOverview = await openWeatherMapService.GetWeatherOneCallOverviewAsync(latitude, longitude);
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 3.0
OpenWeatherMap retired One Call API 2.5. Version 3.0 of this library migrates to One Call API 3.0 and contains the following breaking changes:
GetWeatherOneCallAsynccalls One Call API 3.0 which requires a "One Call by Call" subscription.GetWeatherOneCallHistoricAsyncwas removed. UseGetWeatherOneCallTimeMachineAsyncinstead. It returnsOneCallTimeMachineInfowith the weather data of the requested timestamp in propertyData. ParameteronlyCurrentis no longer supported by OpenWeatherMap.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 |
3.0
- Migrate One Call API from 2.5 (retired by OpenWeatherMap) to 3.0; requires a "One Call by Call" subscription
- Breaking: GetWeatherOneCallAsync now calls One Call API 3.0 and is no longer obsolete
- Breaking: Replace GetWeatherOneCallHistoricAsync with GetWeatherOneCallTimeMachineAsync (returns OneCallTimeMachineInfo)
- Add GetWeatherOneCallDaySummaryAsync and GetWeatherOneCallOverviewAsync
- Add OneCallOptions.IncludeAlerts, DailyWeatherForecast.Summary and HourlyWeatherForecast.Rain/Snow
- Add Geocoding API: GetLocationsByNameAsync, GetLocationByZipCodeAsync, GetLocationsByCoordinatesAsync
- Add GetAirPollutionForecastAsync and GetAirPollutionHistoryAsync
- Breaking: UnitSystem.Standard returns temperatures in Kelvin (was Celsius)
- Breaking: IOpenWeatherMapService has new members
- 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