Go SDK
Golang SDK for Spice.ai
The Go SDK gospice
is the easiest way to query Spice.ai from Go.
It uses Apache Arrow Flight to efficiently stream data to the client and Apache Arrow Records as data frames.
GoDocs available at pkg.go.dev/github.com/spiceai/gospice.
Requirements
Go 1.22 (or later)
Installation
Get the gospice package.
Usage
1. Import the package.
2. Create a SpiceClient passing in your API key. Get your free API key at spice.ai.
3. Initialize the SpiceClient.
4. Execute a query and get back an Apache Arrow Reader.
5. Iterate through the reader to access the records.
Usage with local Spice runtime
Follow the quickstart guide to install and run spice locally.
Or using custom flight address:
Check Spice OSS documentation 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).
See client_test.go for examples on querying Ethereum and Polygon blocks.
Last updated