```python
streamlit_app.py
import streamlit as st
from gsheetsdb import connect
Create a connection object.
conn = connect()
Perform SQL query on the Google Sheet.
Uses st.cache to only rerun when the query changes or after 10 min.
@st.cache(ttl=600)
def run_query(query):
    rows = conn.execute(query, headers=1)
    return rows
sheet_url = st.secrets["public_gsheets_url"]
rows = run_query(f'SELECT * FROM "{sheet_url}"')
Print results.
for row in rows:
    st.write(f"{row.name} has a :{row.pet}:")
```
See st.cache above? Without it, Streamlit would run the query every time the app reruns (e.g. on a widget interaction). With st.cache, it only runs when the query changes or after 10 minutes (that's what ttl is for). Watch out: If your database updates more frequently, you should adapt ttl or remove caching so viewers always see the latest data. Read more about caching here.
