For the complete documentation index, see llms.txt. This page is also available as Markdown.

Dotnet SDK

Dotnet SDK for Spice.ai

The Dotnet SDK SpiceAI is the easiest way to query Spice.ai from Dotnet.

It uses Apache Arrow Flight to efficiently stream data to the client and Apache Arrow Records as data frames.

Requirements

The package targets .NET Standard 2.0, .NET 8.0, .NET 9.0, and .NET 10.0. .NET 8.0 or later is recommended.

Installation

Add Spice SDK

dotnet add package SpiceAI

Usage

  1. Create a SpiceClient by providing your API key to SpiceClientBuilder. Get your free API key at Spice.ai.

SpiceClient implements IDisposable, so declare it with using.

using Spice;

using var client = new SpiceClientBuilder()
    .WithSpiceCloud("API_KEY")
    .Build();

The builder also accepts WithApiKey(string), WithFlightAddress(string), WithHttpAddress(string), WithMaxRetries(int) (default 3), WithUserAgent(string), and WithTls(bool).

  1. Execute a query and get back an Apache Arrow Flight Client Record Batch Stream Reader.

  1. Iterate through the reader to access the records.

Parameterized queries

QueryWithParams(string sql, params object?[] parameters) binds positional $1, $2 placeholders:

Parameters are positional only. Named placeholders such as :product_id are not supported.

Usage with local Spice runtime

Follow the quickstart guide to install and run spice locally. The builder defaults to the local runtime:

Or using a custom flight address:

Default endpoints

Target
Arrow Flight
HTTP

Spice.ai Cloud

https://flight.spiceai.io:443

https://data.spiceai.io

Local runtime

http://localhost:50051

http://localhost:8090

The Cloud endpoints can be set with SPICE_FLIGHT_URL and SPICE_HTTP_URL, and the local endpoints with SPICE_LOCAL_FLIGHT_URL and SPICE_LOCAL_HTTP_URL.

Refreshing a dataset

RefreshDatasetAsync(string datasetName) triggers a refresh of an accelerated dataset.

Contributing

Contribute to or file an issue with the spice-dotnet library at: https://github.com/spiceai/spice-dotnet

Last updated

Was this helpful?