Fetch prices with PriceFetch API, push them to Google Sheets via gspread, and schedule updates with cron. Your spreadsheet stays current without manual work.
Google Sheets is where a lot of pricing analysis actually happens. Product managers, buyers, and analysts live in spreadsheets. By pushing PriceFetch data directly to Sheets, you skip the manual copy-paste and give stakeholders a live view of pricing data they can filter, chart, and share.
This tutorial connects PriceFetch API to Google Sheets using gspread (a Python library for the Google Sheets API). The result is a spreadsheet that updates automatically on a schedule.
Try it yourself — 500 free API credits, no credit card required.
Start FreeYou need a Google Cloud service account to write to Sheets programmatically. This is a one-time setup.
1. Go to console.cloud.google.com and create a new project 2. Enable the Google Sheets API and Google Drive API 3. Create a service account (APIs & Services > Credentials > Create Credentials > Service Account) 4. Download the JSON key file and save it as `service_account.json` in your project directory 5. Share your target Google Sheet with the service account email (it looks like `name@project.iam.gserviceaccount.com`)
Keep the service account JSON file out of git — add it to `.gitignore`.
pip install gspread httpx
# Add to .gitignore
echo "service_account.json" >> .gitignoreThe script reads product URLs from the first column of your spreadsheet, fetches prices from PriceFetch, and writes the results to adjacent columns. This means you can add new products by just pasting URLs into column A.
The sheet format: Column A = Product URL, Column B = Product Name (optional), Column C = Price, Column D = Currency, Column E = In Stock, Column F = Last Updated.
import gspread
import httpx
import os
from datetime import datetime
API_KEY = os.environ["PRICEFETCH_API_KEY"]
def update_sheet(spreadsheet_name: str) -> None:
"""Fetch prices and update Google Sheet."""
# Connect to Google Sheets
gc = gspread.service_account(filename="service_account.json")
sheet = gc.open(spreadsheet_name).sheet1
# Get all URLs from column A (skip header row)
urls = sheet.col_values(1)[1:] # Skip header
if not urls:
print("No URLs found in column A")
return
print(f"Fetching prices for {len(urls)} products...")
for i, url in enumerate(urls, start=2): # Row 2 onwards (1-indexed, skip header)
if not url.strip():
continue
resp = httpx.get(
"https://api.pricefetch.dev/v1/price",
params={"url": url.strip()},
headers={"X-API-Key": API_KEY},
timeout=15.0,
)
data = resp.json()
if data["success"]:
d = data["data"]
sheet.update(f"C{i}:F{i}", [[
d["price"],
d["currency"],
"Yes" if d["in_stock"] else "No",
datetime.now().strftime("%Y-%m-%d %H:%M"),
]])
print(f" Row {i}: {d['currency']} {d['price']}")
else:
sheet.update(f"C{i}:F{i}", [[
"Error",
data["error"]["code"],
"",
datetime.now().strftime("%Y-%m-%d %H:%M"),
]])
print(f" Row {i}: Error - {data['error']['code']}")
print("Sheet updated.")
if __name__ == "__main__":
update_sheet("Price Tracker")To track price history in the same spreadsheet, add a second sheet (tab) that logs every price check with a timestamp. This gives you a running log you can chart with Sheets' built-in chart tools.
The append approach means the history sheet grows over time. Google Sheets handles up to 10 million cells, so you won't run out of space for a long time.
def append_history(spreadsheet_name: str, url: str, price: float, currency: str, in_stock: bool) -> None:
"""Append a price data point to the History sheet."""
gc = gspread.service_account(filename="service_account.json")
spreadsheet = gc.open(spreadsheet_name)
# Get or create History sheet
try:
history = spreadsheet.worksheet("History")
except gspread.WorksheetNotFound:
history = spreadsheet.add_worksheet("History", rows=1000, cols=6)
history.update("A1:F1", [["Timestamp", "URL", "Price", "Currency", "In Stock", "Retailer"]])
history.append_row([
datetime.now().strftime("%Y-%m-%d %H:%M"),
url,
price,
currency,
"Yes" if in_stock else "No",
])Schedule the script with cron to keep your spreadsheet current. Daily updates work well for most use cases. If you need real-time data, consider running it every few hours.
Google Sheets API has its own rate limits (60 requests per minute per user), but since we're updating one row at a time, you'd need hundreds of products to hit them. For very large product lists, batch the updates using gspread's batch_update method.
# Update prices daily at 8 AM
0 8 * * * cd /path/to/project && source .env && python sheets_updater.py
# Or twice daily
0 8,20 * * * cd /path/to/project && source .env && python sheets_updater.pySign up in 30 seconds. No credit card required. One credit per successful API call.