Metadata-Version: 2.4
Name: pystarburst
Version: 0.17.0
Summary: PyStarburst DataFrame API allows you to query and transform data in Starburst products in a data pipeline without having to download the data locally.
License: Apache-2.0
License-File: LICENSE.txt
Author: Starburst Data
Author-email: info@starburstdata.com
Requires-Python: >=3.10,<3.15
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Provides-Extra: pandas
Provides-Extra: pyarrow
Requires-Dist: certifi (>=2026.10.18)
Requires-Dist: idna (>=3.15)
Requires-Dist: numpy (>=2.0.0) ; (python_version >= "3.11" and python_version < "3.14") and (extra == "pandas")
Requires-Dist: numpy (>=2.0.0,<2.3.0) ; (python_version == "3.10") and (extra == "pandas")
Requires-Dist: numpy (>=2.4.0) ; (python_version >= "3.14") and (extra == "pandas")
Requires-Dist: orjson (>=3.11.6)
Requires-Dist: pandas (>=2.3.3,<3) ; extra == "pandas"
Requires-Dist: pyarrow (>=25.0.0,<26) ; extra == "pyarrow"
Requires-Dist: pydantic (>=2.14.4,<3)
Requires-Dist: requests (>=2.33.0)
Requires-Dist: trino (>=0.340.0)
Requires-Dist: urllib3 (>=2.8.0)
Requires-Dist: zstandard (>=0.23.0,<0.24.0)
Project-URL: Homepage, https://starburst.io
Project-URL: Repository, https://github.com/starburstdata/pystarburst-examples
Description-Content-Type: text/markdown

# PyStarburst DataFrame API

PyStarburst DataFrame API allows you to query and transform data in Starburst products in a data pipeline without having to download the data locally.

## Documentation

See the PyStarburst API [documentation](https://pystarburst.eng.starburstdata.net/) and the examples [repository](https://github.com/starburstdata/pystarburst-examples).

## Getting started

Install pystarburst

```bash
pip install pystarburst
```

### Connect to a Starburst server

The parameters are the same connect parameters as in Trino Python Client.

```python
from pystarburst import Session

connection_parameters = {
    "host": "localhost",
    "port": 8080,
    "user": "admin",
    "catalog": "tpch",
    "schema": "tiny"
}

session = Session.builder.configs(connection_parameters).create()
```

### Using SQL

```python
from pystarburst import Session

session = Session.builder.configs({ ... }).create()

session.sql("SELECT 1 as a").show()
```

### Querying a table

```python
from pystarburst import Session

session = Session.builder.configs({ ... }).create()

df = session.table("nation")
print(df.schema)
df.show()

```

### Filtering a data frame

```python
from pystarburst import Session

session = Session.builder.configs({ ... }).create()

df = session.table("nation")
df.filter(df.col("regionkey") == 0).show()
```

### Joining data frames

```python
from pystarburst import Session

session = Session.builder.configs({ ... }).create()

df = session.table("nation")
df.filter(df.col("regionkey") == 0).show()
```

### Aggregation

```python
from pystarburst import Session
from pystarburst.functions import col

session = Session.builder.configs({ ... }).create()
df = session.table("nation")
df.agg((col("regionkey"), "max"), (col("regionkey"), "avg")).show()
```

### Arrow spooling

With a server configured to use Arrow encoding, `DataFrame` methods `to_arrow_batches()`, `to_arrow_table()` and `to_pandas()` use Arrow IPC spooling with parallel segment decoding for significantly faster transfer of large result sets.

```bash
pip install pystarburst[pyarrow]
```

```python
from pystarburst import Session

session = Session.builder.configs({...}).create()

pandas_df = session.sql("SELECT * FROM nation").to_pandas()
# or
arrow_reader = session.sql("SELECT * FROM nation").to_arrow_batches()
# or
arrow_table = session.sql("SELECT * FROM nation").to_arrow_table()
```
Of the three methods: `to_arrow_batches()`, `to_arrow_table()` and `to_pandas()`, `to_arrow_batches()` is the most memory efficient, as it returns
`pyarrow.RecordBatchReader` that can iterate over record batches without materializing the entire result set in memory.

Arrow encoding is used only for those three methods. All other operations (`collect()`, `show()`, etc.) use the default encoding.

By default, PyStarburst requests Arrow encodings `arrow+zstd`, `arrow+lz4` and `arrow`, in that order, from the server.
The property `arrow_encoding` may be used to override encoding preferences. For example, to prefer uncompressed Arrow data but
accept zstd-compressed if the server does not support uncompressed Arrow, set `arrow_encoding` as follows:

```python
session = Session.builder.configs({"arrow_encoding": "arrow,arrow+zstd", ...}).create()
```

