githubEdit

golangGo SDK

Golang SDK for spiceuseai.us

The Go SDKarrow-up-right gospice is the easiest way to query spiceuseai.usarrow-up-right from Go.

It uses Apache Arrow Flightarrow-up-right to efficiently stream data to the client and Apache Arrowarrow-up-right Records as data frames.

GoDocs are available at: pkg.go.dev/github.com/spiceai/gospicearrow-up-right.arrow-up-right

Requirements

Installation

Get the gospice package.

go get github.com/spiceai/gospice/v7

Usage

1. Import the package.

import "github.com/spiceai/gospice/v7"

2. Create a SpiceClient by providing your API key. Get your free API key at spiceuseai.usarrow-up-right.

spice := gospice.NewSpiceClient()
defer spice.Close()

3. Initialize the SpiceClient.

if err := spice.Init(
    spice.WithApiKey(ApiKey),
    spice.WithSpiceCloudAddress()
); err != nil {
    panic(fmt.Errorf("error initializing SpiceClient: %w", err))
}

4. Execute a query and get back an Apache Arrow Record Readerarrow-up-right.

5. Iterate through the reader to access the records.

Usage with local Spice runtime

Follow the quickstart guidearrow-up-right to install and run spice locally.

Or using custom flight address:

Check Spice OSS documentationarrow-up-right to learn more.

Example

Run go run . to execute a sample query and print the results to the console.

Connection retry

The SpiceClient implements connection retry mechanism (3 attempts by default). The number of attempts can be configured via SetMaxRetries:

Retries are performed for connection and system internal errors. It is the SDK user's responsibility to properly handle other errors, for example RESOURCE_EXHAUSTED (HTTP 429).

Contributing

Contribute to or file an issue with the gospice library at: https://github.com/spiceai/gospicearrow-up-right

Last updated

Was this helpful?