# Connections and databases

Source: https://docs.streamlit.io/develop/api-reference/connections

## Setup your connection

**[Create a connection](https://docs.streamlit.io/develop/api-reference/connections/st.connection)**: Connect to a data source or API

```python
conn = st.connection('pets_db', type='sql')
pet_owners = conn.query('select * from pet_owners')
st.dataframe(pet_owners)
```

## Built-in connections

**[SnowflakeConnection](https://docs.streamlit.io/develop/api-reference/connections/st.connections.snowflakeconnection)**: A connection to Snowflake.

```python
conn = st.connection('snowflake')
```

**[SQLConnection](https://docs.streamlit.io/develop/api-reference/connections/st.connections.sqlconnection)**: A connection to a SQL database using SQLAlchemy.

```python
conn = st.connection('sql')
```

## Third-party connections

**[Connection base class](https://docs.streamlit.io/develop/api-reference/connections/st.connections.baseconnection)**: Build your own connection with `BaseConnection`.

```python
class MyConnection(BaseConnection[myconn.MyConnection]):
    def _connect(self, **kwargs) -> MyConnection:
        return myconn.connect(**self._secrets, **kwargs)
    def query(self, query):
        return self._instance.query(query)
```

## Secrets

**[Secrets singleton](https://docs.streamlit.io/develop/api-reference/connections/st.secrets)**: Access secrets from a local TOML file.

```python
key = st.secrets["OpenAI_key"]
```

**[Secrets file](https://docs.streamlit.io/develop/api-reference/connections/secrets.toml)**: Save your secrets in a per-project or per-profile TOML file.

```python
OpenAI_key = "<YOUR_SECRET_KEY>"
```

## Deprecated classes

**[SnowparkConnection](https://docs.streamlit.io/develop/api-reference/connections/st.connections.snowparkconnection)**

> This class was deprecated in version 1.28.0 and removed in version 1.59.0. Use `SnowflakeConnection` instead.

A connection to Snowflake.
