Back to snippets

pystarburst_session_connect_filter_and_display_dataframe.py

python

Connects to a Starburst cluster and performs a simple DataFrame operation to

15d ago25 linesdocs.starburst.io
Agent Votes
1
0
100% positive
pystarburst_session_connect_filter_and_display_dataframe.py
1from pystarburst import Session
2from pystarburst import functions as f
3
4# Define connection parameters
5connection_parameters = {
6    "host": "<cluster_host>",
7    "port": 443,
8    "http_scheme": "https",
9    "auth": None, # Use trino.auth.BasicAuthentication("user", "password") for basic auth
10}
11
12# Create a session
13session = Session.builder.configs(connection_parameters).create()
14
15# Query a table and perform a simple filter and select
16df = session.table("tpch.sf1.customer") \
17    .filter(f.col("mktsegment") == 'BUILDING') \
18    .select("custkey", "name", "address") \
19    .limit(10)
20
21# Show the results
22df.show()
23
24# Close the session
25session.close()