---
title: Integrate Streamlit with Tiger Data | Tiger Data Docs
description: Connect Streamlit to Tiger Cloud or self-hosted TimescaleDB to build interactive Python data apps and dashboards.
---

[Streamlit](https://streamlit.io/) is an open-source Python framework for turning data scripts into interactive web apps, without requiring any frontend experience.

This page shows you how to connect a Streamlit app to Tiger Data, so that you can query your data and display it in a live app.

In this integration guide, you:

- Install the packages Streamlit needs to connect to your service or database.
- Store your connection details as a Streamlit secret.
- Load data from your service or database into a DataFrame and display it.

## Prerequisites for this integration guide

To follow these steps, you'll need:

- A [Tiger Cloud service](/get-started/quickstart/create-service/index.md), or a running instance of [self-hosted TimescaleDB](/get-started/choose-your-path/install-timescaledb/index.md).

* Your [connection details](/integrate/find-connection-details/index.md).

- Python 3.9 or later, with `pip` installed.
- [Streamlit](https://docs.streamlit.io/get-started/installation) 1.28 or later, which added the built-in `st.connection` SQL connection.

## Connect Streamlit to your service or database

Streamlit's built-in `st.connection` handles secrets retrieval, connection setup, and query caching for you, using [SQLAlchemy](https://www.sqlalchemy.org/) and the `psycopg2` driver underneath.

1. **Install the required packages**

   In your project's virtual environment, install Streamlit and the PostgreSQL driver:

   Terminal window

   ```
   pip install streamlit psycopg2-binary sqlalchemy
   ```

   `psycopg2-binary` installs the `psycopg2` driver as a prebuilt wheel, so you don't need a local PostgreSQL build toolchain.

2. **Store your connection details as a secret**

   In your project, create `.streamlit/secrets.toml` and add your [connection details](/integrate/find-connection-details/index.md):

   ```
   [connections.tigerdata]
   dialect = "postgresql"
   host = "<host>"
   port = "<port>"
   database = "<dbname>"
   username = "<user>"
   password = "<password>"
   ```

   Tiger Cloud requires an encrypted connection. If your connection fails without it, add `sslmode = "require"` to the `[connections.tigerdata]` section.

   Add `.streamlit/secrets.toml` to `.gitignore` so you don't commit credentials to version control.

3. **Connect and load data into a DataFrame**

   In your app's Python file, open the connection and query your data:

   ```
   import streamlit as st


   conn = st.connection("tigerdata", type="sql")
   df = conn.query("SELECT * FROM <table_name> LIMIT 10;", ttl="10m")


   st.dataframe(df)
   ```

   `st.connection` reads the `[connections.tigerdata]` section from your secrets file by matching the name you pass in. The `ttl` argument caches the query result for 10 minutes; set it to `0` while you're developing to see every change immediately.

## Verify the integration

To confirm Streamlit is working with your service or database:

1. **Run your app**

   From your project directory, start the app:

   Terminal window

   ```
   streamlit run app.py
   ```

2. **Check the rendered data**

   In the browser tab Streamlit opens, you see the DataFrame from your service or database rendered as a table, confirming the connection works.

You have successfully integrated Streamlit with Tiger Data.

## Troubleshooting

- **`ModuleNotFoundError: No module named 'psycopg2'`:** install the `psycopg2-binary` package rather than `psycopg2` unless you have PostgreSQL build tools installed locally.
- **Connection refused or times out:** confirm the host and port, and that your network allows outbound connections from where the app runs. For Tiger Cloud, make sure `sslmode` is set to `require`.
- **`KeyError` on the connection name:** the name passed to `st.connection` (`tigerdata` above) must match the `[connections.<name>]` section in `secrets.toml` exactly.

For other connectivity and authentication issues, see [Troubleshoot Tiger Cloud integrations](/integrate/troubleshooting/index.md).

## Next steps

[Find your connection details](/integrate/find-connection-details/index.md)

[Locate the host, port, database, user, and password for your service or database.](/integrate/find-connection-details/index.md)

[Integrate Tableau with Tiger Data](/integrate/bi-vizualization/tableau/index.md)

[Connect Tableau to your service or database to build dashboards.](/integrate/bi-vizualization/tableau/index.md)
