supabase-csharp 0.11.0

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

// Install supabase-csharp as a Cake Tool
#tool nuget:?package=supabase-csharp&version=0.11.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.

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 1,275 4/5/2024
0.16.1 2,167 3/15/2024
0.16.0 277 3/12/2024
0.15.0 6,414 1/8/2024
0.14.0 2,424 12/16/2023
0.13.7 4,210 11/13/2023
0.13.6 2,647 10/12/2023
0.13.5 805 10/9/2023
0.13.4 292 10/8/2023
0.13.3 2,454 9/15/2023
0.13.2 124 9/15/2023
0.13.1 1,776 8/26/2023
0.13.0 182 8/26/2023
0.12.2 2,478 7/28/2023
0.12.1 2,824 6/29/2023
0.12.0 379 6/26/2023
0.11.1 1,006 6/10/2023
0.11.0 1,259 5/25/2023
0.10.0 1,296 5/14/2023
0.9.1 1,987 4/29/2023
0.9.0 1,110 4/12/2023
0.8.8 1,840 3/29/2023
0.8.7 1,245 3/24/2023
0.8.6 275 3/23/2023
0.8.5 1,404 3/10/2023
0.8.4 668 3/3/2023
0.8.3 2,389 2/28/2023
0.8.2 475 2/26/2023
0.8.1 2,114 2/7/2023
0.8.0 1,328 2/1/2023
0.7.2 548 1/27/2023
0.7.1 742 1/17/2023
0.7.0 383 1/16/2023
0.6.2 3,502 11/22/2022
0.6.1 4,974 11/13/2022
0.6.0 389 11/13/2022
0.5.3 1,471 10/11/2022
0.5.2 1,090 9/13/2022
0.5.1 4,911 8/2/2022
0.5.0 820 7/17/2022
0.4.4 1,947 5/25/2022
0.4.3 729 5/13/2022
0.4.2 580 4/30/2022
0.4.1 519 4/23/2022
0.4.0 1,250 4/15/2022
0.3.5 3,990 4/11/2022
0.3.4 514 3/28/2022
0.3.3 1,326 2/27/2022
0.3.2 508 2/19/2022
0.3.1 1,766 1/21/2022
0.3.0 487 12/30/2021
0.2.12 347 12/29/2021
0.2.11 356 12/25/2021
0.2.10 312 12/24/2021
0.2.9 370 12/10/2021
0.2.8 370 12/4/2021
0.2.7 350 12/3/2021
0.2.6 430 11/30/2021
0.2.5 474 10/31/2021
0.2.4 360 10/29/2021
0.2.3 384 10/26/2021
0.2.2 587 9/26/2021
0.2.1 403 9/16/2021
0.2.0 383 9/15/2021
0.1.9 1,857 9/12/2021
0.1.8-prerelease 203 8/25/2021
0.1.7-prerelease 221 8/14/2021
0.1.6-prerelease 1,034 6/1/2021
0.1.5-prerelease 235 5/26/2021
0.1.4-prerelease 296 2/27/2021
0.1.3-prerelease 197 2/18/2021
0.1.2-prerelease 245 2/18/2021
0.1.1-prerelease 238 2/16/2021
0.1.0-prerelease 233 2/12/2021