title: 'Python SDK' description: 'Connect to Spice using the Python SDK' pagination_prev: null pagination_next: null tags:
github.com/spiceai/spicepy (opens in a new tab)
:::note[Parameterized Queries]
Parameterized queries are supported with sql_with_params() or the params= argument of the query_* helpers. Install with pip install "spicepy[params] @ git+https://github.com/spiceai/spicepy@v4.0.0" for ADBC support. See Parameterized Queries (opens in a new tab) and ADBC (opens in a new tab) for more information.
:::
Requires Python 3.11 or later and Git.
:::warning
spicepy is not published on PyPI. pip install spicepy installs an unrelated package; install from GitHub as shown above.
:::
By default, the Python SDK will connect to a locally running Spice Runtime:
client.sql() returns a streaming Arrow Flight reader. For one-shot results, use client.query_pandas(), query_arrow(), query_pylist(), or query_pydict(). Since spicepy v4, client.query() submits an asynchronous query job and requires a runtime in distributed (scheduler) mode.
To connect to Spice Cloud, specify the required Flight and HTTP URLs to connect to Spice Cloud. DEFAULT_FLIGHT_URL and DEFAULT_HTTP_URL point at us-east-1. For another region, use grpc+tls://<region>-prod-aws-flight.spiceai.io and https://<region>-prod-aws-data.spiceai.io:
By specifying a custom Flight and HTTP URL, the Python SDK can connect to a remote Spice Runtime - for example, a centralised Spice Runtime instance.
Example code:
The SDK supports refreshing an accelerated dataset with the Client.refresh_dataset() method. Refresh a dataset by calling this method on an instance of an SDK client: