# Apache Arrow Flight API

SQL query results can be served via a high-performance [Apache Arrow Flight](https://arrow.apache.org/docs/format/Flight.html) endpoint. Arrow Flight uses the [gRPC](https://grpc.io) protocol for efficient data transfer.

This setup enables high-speed access to your data in [Python](https://arrow.apache.org/docs/python/index.html), [Go](https://pkg.go.dev/github.com/apache/arrow/go/v8), [C++](https://arrow.apache.org/docs/cpp/index.html), [C#](https://github.com/apache/arrow/blob/master/csharp/README.md), [Rust](https://docs.rs/arrow-flight/latest/arrow_flight/), [Java](https://arrow.apache.org/docs/java/index.html), and [C#](https://github.com/apache/arrow/blob/main/csharp/README.md) and makes it easy to use libraries like [Pandas](https://arrow.apache.org/docs/python/pandas.html) and [NumPy](https://arrow.apache.org/docs/python/numpy.html?highlight=numpy).

### SDKs

It's recommended to use the Spice.ai SDKs to connect and query the Arrow Flight endpoint. SDKs are available for [Python](https://github.com/spicehq/docs/blob/trunk/sdks/python-sdk/README.md), [Node.js](https://github.com/spicehq/docs/blob/trunk/sdks/node.js-sdk), [Go](https://github.com/spicehq/docs/blob/trunk/sdks/go.md), [Rust](https://github.com/spicehq/docs/blob/trunk/sdks/rust-sdk/README.md), [Java](https://github.com/spicehq/docs/blob/trunk/sdks/java-sdk.md), and [Dotnet](https://github.com/spicehq/docs/blob/trunk/sdks/dotnet-sdk.md).

In Python, query results can be easily converted to Pandas or NumPy formats.

You may also use Apache's `pyarrow` library directly.

{% hint style="info" %}
**Note on Apple Silicon Macs** - [How do I know if I have Apple Silicon?](https://support.apple.com/en-us/HT211814)

`The spicepy/pyarrow` installation requires [miniforge](https://github.com/conda-forge/miniforge).

See the [Python SDK page](https://github.com/spicehq/docs/blob/trunk/sdks/python-sdk/README.md#m1-macs) for installation steps.
{% endhint %}

### Connecting to the Endpoint

* Endpoint URL: `grpc+tls://flight.spiceai.io`
* Basic Authentication:
  * Username can be set to an empty string
  * Password should be set to the API key of your app

#### Requirements

* [Table](https://github.com/spicehq/cloud-docs/blob/trunk/api/sql-query-api/broken-reference/README.md) names must be fully-qualified. For example `spiceai.quickstart`

### Samples

Find code samples in Python in [Arrow Flight Samples](broken://pages/5qm4BZtfFlkx9Sp2qtGi).

### Troubleshooting

#### Mac/Windows Certificate issue

If you get this error:

`Could not get default pem root certs`

Install the [Let's Encrypt root certificates](https://letsencrypt.org/certificates/).

<details>

<summary><strong>Instructions for macOS</strong></summary>

First download the `roots.pem` file from the Let's Encrypt server:

```bash
curl -Lo isrgrootx1.pem https://letsencrypt.org/certs/isrgrootx1.pem 
```

Before running your code/jupyter notebook the environment variable `GRPC_DEFAULT_SSL_ROOTS_FILE_PATH` must be set to the pem file path. If you are using command from a terminal this can be done from the folder containing `isrgrootx1.pem` with:

```bash
export GRPC_DEFAULT_SSL_ROOTS_FILE_PATH="$PWD/isrgrootx1.pem"
```

The `export` command will set this variable for this specific terminal and thus will need to be run every time you open a new terminal. Additionally you can add to your terminal profile.

Note that `$PWD` is a bash-specific variable that will be replaced by the current directory path. You can download the certificate file `isrgrootx1.pem` in a specific location and inform this path instead of `$PWD`.

</details>

<details>

<summary>Instructions for Windows</summary>

```powershell
@powershell -NoProfile -ExecutionPolicy unrestricted -Command ^
    (new-object System.Net.WebClient).Downloadfile( ^
        'https://letsencrypt.org/certs/isrgrootx1.pem', 'isrgrootx1.pem')
set GRPC_DEFAULT_SSL_ROOTS_FILE_PATH=%cd%\isrgrootx1.pem
```

</details>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.spice.ai/api/runtime-apis/sql-query/apache-arrow-flight-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
