OpenWeatherMap.API 3.0.4

There is a newer version of this package available.
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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="OpenWeatherMap.API" Version="3.0.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="OpenWeatherMap.API" Version="3.0.4" />
                    
Directory.Packages.props
<PackageReference Include="OpenWeatherMap.API" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add OpenWeatherMap.API --version 3.0.4
                    
#r "nuget: OpenWeatherMap.API, 3.0.4"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package OpenWeatherMap.API@3.0.4
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=OpenWeatherMap.API&version=3.0.4
                    
Install as a Cake Addin
#tool nuget:?package=OpenWeatherMap.API&version=3.0.4
                    
Install as a Cake Tool

OpenWeatherMap.API

Version Downloads Buy Me a Coffee

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:

  • GetWeatherOneCallAsync calls One Call API 3.0 which requires a "One Call by Call" subscription.
  • GetWeatherOneCallHistoricAsync was removed. Use GetWeatherOneCallTimeMachineAsync instead. It returns OneCallTimeMachineInfo with the weather data of the requested timestamp in property Data. Parameter onlyCurrent is no longer supported by OpenWeatherMap.
  • UnitSystem.Standard returns temperatures in Kelvin (as provided by OpenWeatherMap) instead of Celsius.
  • IOpenWeatherMapService has new members. Custom implementations of this interface need to be extended.
  • CurrentWeatherForecast.Rain and CurrentWeatherForecast.Snow are 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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
Loading failed

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