Spice.ai client library for Python.
pip install git+https://github.com/spiceai/spicepy@v2.0.0
Follow the quickstart guide to install and run spice locally
from spicepy import Client
client = Client()
data = client.query('SELECT trip_distance, total_amount FROM taxi_trips ORDER BY trip_distance DESC LIMIT 10;', timeout=5*60)
pd = data.read_pandas()
SQL Query
from spicepy import Client
client = Client(
api_key='API_KEY',
flight_url="grpc+tls://flight.spiceai.io"
)
data = client.query('SELECT * FROM taxi_trips LIMIT 10;', timeout=5*60)
pd = data.read_pandas()
Querying data is done through a Client
object that initialize the connection with Spice endpoint. Client
has the following arguments:
- api_key (string, required): API key to authenticate with the endpoint.
- url (string, optional): URL of the endpoint to use (default: grpc+tls://flight.spiceai.io; firecache: grpc+tls://firecache.spiceai.io)
- tls_root_cert (Path or string, optional): Path to the tls certificate to use for the secure connection (omit for automatic detection)
- user_agent (string, optional): A custom
User-Agent
string to pass when connecting to Spice. Usespicepy.config.get_user_agent
to build the customUser-Agent
Once a Client
is obtained queries can be made using the query()
function. The query()
function has the following arguments:
- query (string, required): The SQL query.
- timeout (int, optional): The timeout in seconds.
A custom timeout can be set by passing the timeout
parameter in the query
function call. If no timeout is specified, it will default to a 10 min timeout then cancel the query, and a TimeoutError exception will be raised.
Check out our Documentation to learn more about how to use the Python SDK.