Connections and databases
Setup your connection
![screenshot](/images/api/connection.jpg)
Create a connection
Connect to a data source or API
conn = st.experimental_connection('pets_db', type='sql')
pet_owners = conn.query('select * from pet_owners')
st.dataframe(pet_owners)
Built-in connections
![screenshot](/images/api/connections.SQLConnection.jpg)
SQLConnection
A connection to a SQL database using SQLAlchemy.
conn = st.experimental_connection('sql')
![screenshot](/images/api/connections.SnowparkConnection.jpg)
SnowparkConnection
A connection to Snowflake Snowpark.
conn = st.experimental_connection('snowpark')
Third-party connections
Connection base class
Build your own connection with ExperimentalBaseConnection
.
class MyConnection(ExperimentalBaseConnection[myconn.MyConnection]):
def _connect(self, **kwargs) -> MyConnection:
return myconn.connect(**self._secrets, **kwargs)
def query(self, query):
return self._instance.query(query)
Still have questions?
Our forums are full of helpful information and Streamlit experts.