Create a Google Sheets Data Entry Form With Python and Streamlit
A Streamlit form that writes submissions straight into a Google Sheet, with the connection configured so credentials sit in the secrets file rather than in your code. Covers select boxes, multi-select and text areas, validating input, and deploying it.
Give the app access
The app talks to Google Sheets through a Google service account: a technical user with its own JSON key. The st-gsheets-connection package uses that key, so install it next to Streamlit with pip install st-gsheets-connection.
-
Create a project in the Google Cloud console and enable the Google Drive API and the Google Sheets API.
-
Create a service account and, under Keys, create a new JSON key. Keep the downloaded file safe; it is the app’s password.
-
Share the spreadsheet with the email address of the service account and give it editor rights.
-
Copy the key into the secrets file of the app, .streamlit/secrets.toml, together with the URL of the spreadsheet.
I explain the service account setup with screenshots of every step in connecting Google Sheets with Streamlit.

The form
The app reads the existing rows from the Vendors worksheet, shows a form with one field per column, checks the input and writes the updated table back to the sheet. Everything sits in one file, streamlit_app.py.
The video uses st.experimental_connection. Streamlit has since replaced it with st.connection, so the code below uses st.connection(“gsheets”, type=GSheetsConnection). conn.read loads the worksheet into a DataFrame; ttl=5 keeps the cached copy for five seconds only, so new rows show up quickly.
The form uses a text input, a select box, a multi-select, a slider, a date input and a text area. Company name and business type are required: when one is empty, or the company already exists, the app shows a warning and stops before writing anything.
import streamlit as st
from streamlit_gsheets import GSheetsConnection
import pandas as pd
# Display Title and Description
st.title("Vendor Management Portal")
st.markdown("Enter the details of the new vendor below.")
# Establishing a Google Sheets connection
conn = st.connection("gsheets", type=GSheetsConnection)
# Fetch existing vendors data
existing_data = conn.read(worksheet="Vendors", usecols=list(range(6)), ttl=5)
existing_data = existing_data.dropna(how="all")
# List of Business Types and Products
BUSINESS_TYPES = [
"Manufacturer",
"Distributor",
"Wholesaler",
"Retailer",
"Service Provider",
]
PRODUCTS = [
"Electronics",
"Apparel",
"Groceries",
"Software",
"Other",
]
# Onboarding New Vendor Form
with st.form(key="vendor_form"):
company_name = st.text_input(label="Company Name*")
business_type = st.selectbox("Business Type*", options=BUSINESS_TYPES, index=None)
products = st.multiselect("Products Offered", options=PRODUCTS)
years_in_business = st.slider("Years in Business", 0, 50, 5)
onboarding_date = st.date_input(label="Onboarding Date")
additional_info = st.text_area(label="Additional Notes")
# Mark mandatory fields
st.markdown("**required*")
submit_button = st.form_submit_button(label="Submit Vendor Details")
# If the submit button is pressed
if submit_button:
# Check if all mandatory fields are filled
if not company_name or not business_type:
st.warning("Ensure all mandatory fields are filled.")
st.stop()
elif existing_data["CompanyName"].str.contains(company_name).any():
st.warning("A vendor with this company name already exists.")
st.stop()
else:
# Create a new row of vendor data
vendor_data = pd.DataFrame(
[
{
"CompanyName": company_name,
"BusinessType": business_type,
"Products": ", ".join(products),
"YearsInBusiness": years_in_business,
"OnboardingDate": onboarding_date.strftime("%Y-%m-%d"),
"AdditionalInfo": additional_info,
}
]
)
# Add the new vendor data to the existing data
updated_df = pd.concat([existing_data, vendor_data], ignore_index=True)
# Update Google Sheets with the new vendor data
conn.update(worksheet="Vendors", data=updated_df)
st.success("Vendor details successfully submitted!")
Deploy
Streamlit Community Cloud deploys the app from GitHub. List the packages in requirements.txt and add the secrets file to .gitignore, so the service account key never ends up in the repository.
Push the code to GitHub, sign in to Streamlit Community Cloud, click New App and select the repository. Because the secrets file is not in the repository, the first start fails with a connection error. Paste the contents of secrets.toml into the Secrets tab of the app settings and the app starts.

Update, delete and log in
The extended version in the repository, vendor_app.py, adds a Choose an Action menu: onboard a vendor, update one, view all vendors or delete one. Each action reads the sheet, changes the DataFrame and writes it back the same way.
Anyone with the link can submit the form. To stop random submissions, put a login screen in front of it, as in my Streamlit login form tutorial.
If your data lives in an Excel file rather than Google Sheets, my free no-code Excel data entry form builder generates a form that saves into the workbook, with no Python to write.

Limits
The app rewrites the whole worksheet on every submit and uses Google Sheets as a simple database. That works well for a small team and a few thousand rows, not for many people submitting at the same moment.
- conn.update writes the complete table. If two people submit within the same few seconds, the second write can overwrite the first.
- The duplicate check uses str.contains, so a new name that appears inside an existing one (“ACME” when “ACME Ltd” exists) is also rejected, and characters like brackets are read as a regular expression. For an exact match, use (existing_data[“CompanyName”] == company_name).any() instead.
- The column names in the code (CompanyName, BusinessType and so on) must match the header row of the sheet exactly.
