supabase-csharp 0.13.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package supabase-csharp --version 0.13.0                
NuGet\Install-Package supabase-csharp -Version 0.13.0                
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="supabase-csharp" Version="0.13.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add supabase-csharp --version 0.13.0                
#r "nuget: supabase-csharp, 0.13.0"                
#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.
// Install supabase-csharp as a Cake Addin
#addin nuget:?package=supabase-csharp&version=0.13.0

// Install supabase-csharp as a Cake Tool
#tool nuget:?package=supabase-csharp&version=0.13.0                

<p align="center"> <img width="300" src=".github/supabase-csharp.png"/> </p> <p align="center"> <img src="https://github.com/supabase/supabase-csharp/workflows/Build%20And%20Test/badge.svg"/> <a href="https://www.nuget.org/packages/supabase-csharp/"> <img src="https://img.shields.io/nuget/vpre/supabase-csharp"/> </a> </p>

Documentation can be found below, on the Supabase Developer Documentation and additionally in the Generated API Docs.

Status

Projects / Examples / Templates

(Create a PR to list your work here!)

Getting Started

If you prefer video format: @Milan Jovanović has created a video crash course to get started!

Care has been taken to mirror, as much as possible, the Javascript Supabase API. As this is an unofficial client, there are times where this client lags behind the offical client. If there are missing features, please open an issue or pull request!

  1. To get started, create a new project in the Supabase Admin Panel.
  2. Grab your Supabase URL and Supabase Public Key from the Admin Panel (Settings → API Keys).
  3. Initialize the client!

Note: supabase-csharp has some APIs that require the service_key rather than the public_key (for instance: the administration of users, bypassing database roles, etc.). If you are using the service_key be sure it is not exposed client side. Additionally, if you need to use both a service account and a public/user account, please do so using a separate client instance for each.

Note for Projects defaulting to System.Text.Json (i.e. Blazor WASM):

You will need to install NewtonsoftJson support:

dotnet add package Microsoft.AspNetCore.Mvc.NewtonsoftJson --version 7.0.5

And include the following in your initialization code:

builder.Services.AddControllers().AddNewtonsoftJson();

Initializing a Client

Initializing a barebones client is pretty simple.

var supabase = new Supabase.Client(SUPABASE_URL, SUPABASE_KEY);
await supabase.InitializeAsync();

Or, using options:

var options = new SupabaseOptions
{
    AutoConnectRealtime = true
};
var supabase = new Supabase.Client(SUPABASE_URL, SUPABASE_KEY, options);

// Calling InitializeAsync will automatically attempt a socket connection if specified in the options.
await supabase.InitializeAsync();

Using the Client

As for actually using the client, each service is listed as a property on Supabase.Client. Some services have helpers to make interactions easier. Properties are provided for every client in the event that advanced customization of the client is needed.

  1. Supabase.Postgrest
    • Is better accessed using supabase.From<ModelName>() as it provides a wrapper class with some helpful accessors (see below)
  2. Supabase.Realtime
    • If used for listening to postgres_changes can be accessed using: supabase.From<ModelName>().On(listenerType, (sender, response) => {})
    • Otherwise, use Supabase.Realtime.Channel("channel_name") for Broadcast and Presence listeners.
// Get the Auth Client
var auth = supabase.Auth;

// Get the Postgrest Client for a Model
var table = supabase.From<TModel>();

// Invoke an RPC Call
await supabase.Rpc("hello_world", null);

// Invoke a Supabase Function
await supabase.Functions.Invoke("custom_function");

// Get the Storage Client
var storageBucket = supabase.Storage.From("bucket_name");

// Use syntax for broadcast, presence, and postgres_changes
var realtime = supabase.Realtime.Channel("room_1");

// Alternatively, shortcut syntax for postgres_changes
await supabase.From<TModel>().On(ListenType.All, (sender, response) =>
{
    switch (response.Event)
    {
        case Constants.EventType.Insert:
            break;
        case Constants.EventType.Update:
            break;
        case Constants.EventType.Delete:
            break;
    }

    Debug.WriteLine($"[{response.Event}]:{response.Topic}:{response.Payload.Data}");
});

Notes

  • Be aware that many of the supabase features require permissions for proper access from a client. This is especially true for realtime, postgres, and storage. If you are having problems getting the client to pull data, verify that you have proper permissions for the logged in user.
  • Connection to Supabase.Realtime is, by default, not enabled automatically, this can be changed in options.
  • When logging in using the Supabase.Auth (Gotrue) client, state is managed internally. The currently logged in user's token will be passed to all the Supabase features automatically (via header injection).
  • Token refresh enabled by default and is handled by a timer on the Gotrue client.
  • Client libraries listed above have additional information in their readme files.

Of course, there are options available to customize the client. Which can be found in Supabase.SupabaseOptions.

Initializing a Client (with Gotrue/Auth Session Persistence)

You can specify a session handler to persist user sessions in your app. For example:

CustomSessionHandler.cs

class CustomSessionHandler : IGotrueSessionPersistence<Session>
{
    public void SaveSession(Session session)
    {
        // Persist Session in Filesystem or in browser storage
        // JsonConvert.SerializeObject(session) will be helpful here!
        throw new NotImplementedException();
    }

    public void DestroySession()
    {
        // Destroy Session on Filesystem or in browser storage
        throw new NotImplementedException();
    }

    public Session LoadSession()
    {
        // Retrieve Session from Filesystem or from browser storage
        // JsonConvert.DeserializeObject<TSession>(value) will be helpful here!
        throw new NotImplementedException();
    }
}

Then initialize using the specified handler:

Main.cs

var options = new SupabaseOptions
{
    // ....
    SessionHandler = new CustomSessionHandler()
};

var supabase = new Supabase.Client(SUPABASE_URL, SUPABASE_KEY, options);

// Calling InitializeAsync will automatically invoke the SessionHandler to setup the internal session state
await supabase.InitializeAsync();

Package made possible through the efforts of:

Join the ranks! See a problem? Help fix it!

<a href="https://github.com/supabase-community/supabase-csharp/graphs/contributors"> <img src="https://contrib.rocks/image?repo=supabase-community/supabase-csharp" /> </a>

Made with contrib.rocks.

Contributing

We are more than happy to have contributions! Please submit a PR.

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. 
.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 was computed. 
.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 (1)

Showing the top 1 NuGet packages that depend on supabase-csharp:

Package Downloads
3ai.solutions.SupabaseWrapper

Simple wrapper to integrate supabase with IdentityUser

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on supabase-csharp:

Repository Stars
supabase-community/supabase-csharp
A C# Client library for Supabase
Version Downloads Last updated
0.16.2 11,587 4/5/2024 0.16.2 is deprecated.
0.16.1 3,898 3/15/2024
0.16.0 418 3/12/2024
0.15.0 9,264 1/8/2024
0.14.0 3,192 12/16/2023
0.13.7 6,761 11/13/2023
0.13.6 3,109 10/12/2023
0.13.5 961 10/9/2023
0.13.4 327 10/8/2023
0.13.3 3,083 9/15/2023
0.13.2 151 9/15/2023
0.13.1 1,965 8/26/2023
0.13.0 208 8/26/2023
0.12.2 2,648 7/28/2023
0.12.1 3,447 6/29/2023
0.12.0 410 6/26/2023
0.11.1 1,055 6/10/2023
0.11.0 1,822 5/25/2023
0.10.0 1,626 5/14/2023
0.9.1 2,497 4/29/2023
0.9.0 1,225 4/12/2023
0.8.8 1,994 3/29/2023
0.8.7 1,289 3/24/2023
0.8.6 307 3/23/2023
0.8.5 1,500 3/10/2023
0.8.4 702 3/3/2023
0.8.3 2,879 2/28/2023
0.8.2 507 2/26/2023
0.8.1 2,320 2/7/2023
0.8.0 1,383 2/1/2023
0.7.2 580 1/27/2023
0.7.1 773 1/17/2023
0.7.0 428 1/16/2023
0.6.2 3,550 11/22/2022
0.6.1 8,126 11/13/2022
0.6.0 415 11/13/2022
0.5.3 1,507 10/11/2022
0.5.2 1,150 9/13/2022
0.5.1 5,408 8/2/2022
0.5.0 850 7/17/2022
0.4.4 2,015 5/25/2022
0.4.3 761 5/13/2022
0.4.2 619 4/30/2022
0.4.1 546 4/23/2022
0.4.0 1,396 4/15/2022
0.3.5 4,020 4/11/2022
0.3.4 575 3/28/2022
0.3.3 1,355 2/27/2022
0.3.2 549 2/19/2022
0.3.1 1,807 1/21/2022
0.3.0 537 12/30/2021
0.2.12 378 12/29/2021
0.2.11 381 12/25/2021
0.2.10 344 12/24/2021
0.2.9 401 12/10/2021
0.2.8 396 12/4/2021
0.2.7 375 12/3/2021
0.2.6 482 11/30/2021
0.2.5 502 10/31/2021
0.2.4 392 10/29/2021
0.2.3 417 10/26/2021
0.2.2 613 9/26/2021
0.2.1 427 9/16/2021
0.2.0 411 9/15/2021
0.1.9 2,083 9/12/2021
0.1.8-prerelease 231 8/25/2021
0.1.7-prerelease 249 8/14/2021
0.1.6-prerelease 1,056 6/1/2021
0.1.5-prerelease 264 5/26/2021
0.1.4-prerelease 320 2/27/2021
0.1.3-prerelease 228 2/18/2021
0.1.2-prerelease 278 2/18/2021
0.1.1-prerelease 270 2/16/2021
0.1.0-prerelease 265 2/12/2021