Clone wiki

Anabranch.MagicSeaweedClient / Home


A .NET library to help you interact with the MagicSeaweed Forecast API

How to install?

Using the Nuget package you can add the client to your .NET project.

Release notes

  • Latest version is 4.1
  • Build status

Release 4.1

This has 2 breaking changes:


  • Namespace is now Anabranch.MagicSeaweed (change from Anabranch.MagicSeaweed.Api) - This is to remove cruft.
  • Client class is now MagicSeaweedClient (change from MagicSeaweed) - This is to make it clearer that it's a client.


  • Async method overloads for all the methods that were there beforehand!

Quick example usage

These are just some quick samples of how to use the SDK.

Get the current forecast

    string apiKey = "YOUR API KEY";

    IMagicSeaweedClient msw = new MagicSeaweedClient(apiKey);
    Forecast forecast = msw.GetCurrentForecast(958); //958 = Widemouth Bay

    Console.WriteLine("Forecast at {0}", forecast.LocalTimestamp);
    Console.WriteLine("Primary swell direction: {0}", forecast.Swell.Components.Primary.Direction);

Get the full 3 day forecast

    IEnumerable<Forecast> forecasts = msw.GetFullForecast(958);


Want results in the US format (ft, mph, f)? What about EU (m, kph, c)? No problem, the default is UK (ft, mph, c), but if you want to change it simply call any of the methods with the units parameter:

    Forecast forecastUk = msw.GetCurrentForecast(958, Units.UK);
    Forecast forecastEu = msw.GetCurrentForecast(958, Units.EU);
    Forecast forecastUs = msw.GetCurrentForecast(958, Units.US);

Specific Fields

You can get specific fields from the forecast (rather than the entire forecast), just pass in an array of Field items - which you can manually create yourself, or use the 'Fields' helper class.

Get just the Local Timestamp field

This returns a Forecast instance, where the LocalTimestamp is the only value set.

    Forecast forecast = msw.GetCurrentForecast(958, fields: new [] {Fields.LocalTimestamp});

Get the Local Timestamp and Wind Chill field

This returns a Forecast instance, where the LocalTimestamp and the Wind.Chill property are set.

    Forecast forecast = msw.GetCurrentForecast(958, fields: new [] {Fields.LocalTimestamp, Fields.Wind.Chill});

Custom classes

You may not want to pass around an empty (bar one property) instance of a Forecast, in which case you can do the following:

    public class MyData { public DateTime LocalTimestamp { get;set;} }

    MyData myData = msw.GetCurrentForecast<MyData>(958, fields: new [] {Fields.LocalTimestamp});

In essence the 'GetCurrentForecast' overload without the generic type is just calling:



You can combine the Units and Fields calls:

    Forecast forecast = msw.GetCurrentForecast(958, Units.EU, new [] {Fields.LocalTimestamp, Fields.Wind.Chill});


Lets say we have the following method:

    private static async Task WriteOutPrimaryDirection(IMagicSeaweedClient msw, int pos)
        var forecast = await msw.GetCurrentForecastAsync(958);
        Console.WriteLine("{0} Finished - {1}", pos, forecast.Swell.Components.Primary.Direction);

We can call it like:

    for(int i = 0; i < 10; i++)
        WriteOutPrimaryDirection(msw, i);

aaaand we get output similar to (but unlikely to be exactly the same) this: (note the numbers are not in order)

0 Finished - 84.63
1 Finished - 84.63
3 Finished - 84.63
5 Finished - 84.63
7 Finished - 84.63
9 Finished - 84.63
2 Finished - 84.63
4 Finished - 84.63
6 Finished - 84.63
8 Finished - 84.63