Python SDK
The Python SDK spicepy
is the easiest way to use and query Spice.ai in Python.
The Python SDK uses Apache Apache Flight to efficiently stream data to the client and Apache Arrow Records as data frames which are then easily converted to Pandas data frames.
Requirements
Python 3.11+
The following packages are required and will be automatically installed by pip:
pyarrow
pandas
certify
requests
Installation
Install the spicepy
package directly from the Spice Github Repository at https://github.com/spiceai/spicepy:
Usage
Import spicepy
and create a Client
by providing your API Key.
You can then submit queries using the query function.
Querying data is done through a Client
object that initializes the connection with the Spice.ai endpoint. Client
has the following arguments:
api_key (string, optional): Spice.ai API key to authenticate with the endpoint.
url (string, optional): URL of the endpoint to use (default: grpc+tls://flight.spiceai.io)
tls_root_cert (Path or string, optional): Path to the tls certificate to use for the secure connection (ommit for automatic detection)
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.
Usage with local Spice runtime
Follow the quickstart guide to install and run spice locally.
Check Spice OSS documentation to learn more.
Contributing
Contribute to or file an issue with the spicepy
library at https://github.com/spiceai/spicepy
Last updated