How to Integrate Streamlit and BigQuery Safely

Published
Length
4 min read

Luis Felipe Dias

All posts

Teams pair streamlit and bigquery to build fast data apps on live cloud tables. The Python app sends queries to the cloud warehouse and renders charts for users. This setup helps data teams share insights without building a full frontend from scratch. Still, linking a web app to a cloud warehouse brings clear safety risks. You must manage who logs in, what queries run, and what data returns. How data and roles flow between streamlit and bigquery In a standard setup, the Python app runs on a s

Your coding agents run with your access.

Claude Code reaches prod with a developer's credentials, and approval prompts get clicked through. hoop.dev checks every query, masks sensitive data, and holds risky changes for a human.

Teams pair streamlit and bigquery to build fast data apps on live cloud tables. The Python app sends queries to the cloud warehouse and renders charts for users. This setup helps data teams share insights without building a full frontend from scratch. Still, linking a web app to a cloud warehouse brings clear safety risks. You must manage who logs in, what queries run, and what data returns.

How data and roles flow between streamlit and bigquery

In a standard setup, the Python app runs on a server or cloud container. When a user opens the page, the app script runs from top to bottom. The script uses a cloud client library to send a query to the warehouse. BigQuery checks the cloud role attached to that request before it reads any table. If the role has the right permissions, the warehouse runs the job and returns rows. The app then turns those rows into tables, metrics, or charts on the screen.

You can handle identity between the two tools in two main ways. First, the app can use one service account to run all queries for everyone. Second, the app can ask each user to log in with their own identity. The first path is quick to set up, but it hides who asked for the data. The second path keeps an audit trail per person, though it takes more work. For production apps, tying queries to real user identities is the safer choice.

Data caching also changes how these two tools talk to each other. If ten users open the same dashboard, you do not want ten big scans. The app can store query results in memory for a short time. Still, cached data can leak across users if you do not scope it well. Always key your cache by user role when different people have different table rules.

Common failure modes with shared keys and broad roles

Many teams start by putting a service account key file on the app server. They give that account broad project roles so every chart works right away. This shortcut creates a major risk if someone leaks the code or server files. Anyone with that static key can read or drop tables from outside your network. Instead of static key files, use workload identity features from your cloud host. That way, the runtime gets short-lived credentials without storing a secret file on disk.

Overbroad table permissions are another common failure mode in data apps. An app that only needs to read one summary view should not read raw tables. Create a dedicated dataset with clean views just for the web app to read. Grant the app role read permissions on that single dataset and nothing else. This step also stops bad inputs from touching sensitive tables in other projects.

BigQuery IAM + End-to-End Encryption: architecture patterns and best practices

Continue reading? Get the full guide.

Free. No spam. Unsubscribe anytime.

Unlogged queries and runaway costs also hurt production teams over time. When every user click triggers a full table scan, warehouse bills climb fast. Set query byte limits on the warehouse project or on the specific service account. Also, attach custom labels to jobs sent from the app so you can track usage. Finally, if tables hold emails, phone numbers, card numbers, or national IDs, apply masking. Data masking rewrites matched fields in results before they reach the browser screen.

Scoping network paths and audit logs for production

Good role setup works best when paired with tight network rules. Do not expose the app server to the open web without a login check. Place the app inside a private network and require team single sign-on first. Configure private cloud routing so traffic to the warehouse stays on the cloud backbone. Check your warehouse audit logs each week to spot strange queries or high scan volumes. Clear logs and small roles keep both your app and your warehouse safe.

Check database and API queries on the wire

Identity tools, roles, and network rules decide who opens a session. Setup alone cannot check what each query does or mask sensitive values in a response once a session starts. When workflows touch Postgres, MySQL, SQL Server, MongoDB, ClickHouse, Kubernetes APIs, SSH, or internal HTTP APIs, hoop.dev runs beside those services as an open-source proxy, a sidecar for your Postgres or API. It inspects requests coming in and results going back on the wire.

Your login details and client tools stay as they are while hoop.dev guardrails refuse bad deletes or drops before they run. On responses, hoop.dev data masking rewrites matched sensitive values in memory. Furthermore, hoop.dev holds SOC 2 Type II, is MIT licensed, and writes every query and decision to an audit trail that generates evidence for HIPAA, GDPR, and PCI DSS. See the source on GitHub.

Frequently asked questions

Should I use a single service account for my whole Streamlit app?

A single service account is fine for public or internal summary dashboards with open data. If the app shows sensitive rows, use per-user login or strict row-level rules instead. Always scope any shared account to read only the exact views the app needs.

How do I stop users from running expensive BigQuery scans from the app?

Set a maximum bytes billed limit on the query job settings or project quota. Use partitioned and clustered tables so filters scan only small slices of data. You should also cache common query results in the app to cut repeat runs.

What is the safest way to handle personal data in dashboard results?

Avoid pulling raw personal columns into the app memory whenever summary metrics will work. For columns like emails, phone numbers, card numbers, or national IDs, use dynamic masking. Masking rewrites matched fields in results so the app displays safe values.

The query runs. The emails stay hidden.