8000 Add Spice Cloud SDK sample snippets by ewgenius · Pull Request #207 · spiceai/cookbook · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Add Spice Cloud SDK sample snippets #207

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the communi 8000 ty.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions client-sdk/gospice-sdk-sample/main_cloud.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package main

import (
"context"
"fmt"

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

func main() {
spice := gospice.NewSpiceClient()
defer spice.Close()

err := spice.Init(
gospice.WithApiKey("API_KEY"),
gospice.WithHttpAddress("https://data.spiceai.io"),
gospice.WithFlightAddress("flight.spiceai.io:443"),
)
if err != nil {
panic(fmt.Errorf("Error initializing client: %s", err))
}

reader, err := spice.Query(context.Background(), "show tables;")
if err != nil {
panic(fmt.Errorf("error querying: %w", err))
}
defer reader.Release()

for reader.Next() {
record := reader.Record()
defer record.Release()

fmt.Printf("%v\n", record)
}
}
26 changes: 26 additions & 0 deletions client-sdk/spice-rs-sdk-sample/src/main_cloud.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use spiceai::{ClientBuilder, StreamExt};

#[tokio::main]
async fn main() {
let mut client = ClientBuilder::new()
.api_key("API_KEY")
.flight_url("https://flight.spiceai.io")
.build()
.await
.unwrap();

let mut flight_data_stream = client
.query("show tables;")
.await
.expect("Error executing query");

while let Some(batch) = flight_data_stream.next().await {
match batch {
Ok(batch) => {
/* process batch */
println!("{:?}", batch)
}
Err(_) => { /* handle error */ }
};
}
}
17 changes: 17 additions & 0 deletions client-sdk/spice.js-sdk-sample/index_cloud.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* npm install @spiceai/spice --save
* or
* yarn add @spiceai/spice
*/
import { SpiceClient } from "@spiceai/spice";

const main = async () => {
const spiceClient = new SpiceClient({
api_key: "API_KEY",
http_url: "https://data.spiceai.io",
flight_url: "flight.spiceai.io:443",
});
const table = await spiceClient.query(`show tables;`);
console.table(table.toArray());
};

main();
11 changes: 11 additions & 0 deletions client-sdk/spicepy-sdk-sample/main_cloud.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Install with: pip install git+https://github.com/spiceai/spicepy
from spicepy import Client

client = Client(
api_key='API_KEY',
flight_url="grpc+tls://flight.spiceai.io"
)
data = client.query('show tables;', timeout=5*60)
pd = data.read_pandas()

print(pd)
0