Published
Google Finance API in Python: Get Stock Quotes and Market Data as JSON
Google shut down its official Google Finance API more than a decade ago, and the GOOGLEFINANCE function only works inside Google Sheets. If you want Google Finance quotes in Python, for a watchlist, a dashboard, alerts, or research, you need an API that reads the Google Finance page and returns it as JSON. This guide uses PrismCrawl's Google Finance API to fetch stock quotes, read market overviews, and log prices over time. It needs only Python 3 and the requests package.
Set up
Create a PrismCrawl account to get an API key and 100 free credits, then store the key in an environment variable:
pip install requests
export PRISMCRAWL_API_KEY="replace-with-your-key"
Each successful request uses one credit, and failed requests are free.
Get a stock quote
The Google Finance endpoint takes a Google Finance identifier: the ticker and exchange separated by a colon, as in the Google Finance URL. Examples are NVDA:NASDAQ, AAPL:NASDAQ, JPM:NYSE, and BTC-USD for Bitcoin.
import os
import requests
API_BASE = "https://api.prismcrawl.com/v1/google"
def prismcrawl(path: str, body: dict) -> dict:
response = requests.post(
f"{API_BASE}/{path}",
headers={
"x-api-key": os.environ["PRISMCRAWL_API_KEY"],
"content-type": "application/json",
},
json=body,
timeout=30,
)
response.raise_for_status()
payload = response.json()
if not payload.get("success"):
raise RuntimeError(payload.get("error", "Google Finance request failed"))
return payload["data"]["content"]
def get_quote(symbol: str) -> dict:
content = prismcrawl("finance", {"id": symbol, "language": "en"})
return content["results"][0]
quote = get_quote("NVDA:NASDAQ")
print(quote)
The response looks like this:
{
"id": "NVDA:NASDAQ",
"title": "NVIDIA Corp (NVDA)",
"price": "$226.99",
"price_change": "+0.67",
"percentage_change": "+0.30%",
"url": "https://www.google.com/finance/quote/NVDA:NASDAQ"
}
Convert prices to numbers
Google Finance returns values as display text, with currency symbols, thousands separators, and signs. Convert them before doing math:
import re
def to_number(text: str | None) -> float | None:
if not text:
return None
cleaned = re.sub(r"[^0-9.+-]", "", text)
try:
return float(cleaned)
except ValueError:
return None
price = to_number(quote["price"]) # 226.99
change = to_number(quote["price_change"]) # 0.67
change_pct = to_number(quote["percentage_change"]) # 0.3
Keep the original text as well. When a currency symbol is present it tells you the quote currency, which differs by exchange; some quotes, such as BTC-USD, have no symbol.
Read the market overview
The Google Finance markets endpoint returns the items on Google Finance's markets page, such as indexes and sector benchmarks, in the same shape. Set limit to control how many items you get:
markets = prismcrawl("finance/markets", {"language": "en", "limit": 20})
for item in markets["results"]:
print(f'{item["title"]:<30} {item["price"]:>12} {item["percentage_change"]:>8}')
Build a watchlist that logs prices
To track prices over time, request each symbol on a schedule and append the results to a CSV file:
import csv
from datetime import datetime, timezone
from pathlib import Path
WATCHLIST = ["NVDA:NASDAQ", "AAPL:NASDAQ", "MSFT:NASDAQ", "JPM:NYSE"]
LOG_FILE = Path("quotes.csv")
def log_quotes() -> None:
new_file = not LOG_FILE.exists()
collected_at = datetime.now(timezone.utc).isoformat()
with LOG_FILE.open("a", newline="") as handle:
writer = csv.writer(handle)
if new_file:
writer.writerow(["collected_at", "symbol", "price", "change", "change_pct", "price_text"])
for symbol in WATCHLIST:
try:
quote = get_quote(symbol)
except (requests.RequestException, RuntimeError) as error:
print(f"{symbol}: {error}")
continue
writer.writerow(
[
collected_at,
symbol,
to_number(quote["price"]),
to_number(quote["price_change"]),
to_number(quote["percentage_change"]),
quote["price"],
]
)
log_quotes()
Run log_quotes() from cron or a scheduler. Logging four symbols every 15 minutes during a 6.5-hour US trading day is about 2,200 requests a month, which the $5 package covers several times over.
Add an alert
Compare each new quote with a threshold and send a message when it moves:
def check_alerts(threshold_pct: float = 3.0) -> list[str]:
alerts = []
for symbol in WATCHLIST:
quote = get_quote(symbol)
change_pct = to_number(quote["percentage_change"])
if change_pct is not None and abs(change_pct) >= threshold_pct:
alerts.append(f'{quote["title"]} moved {quote["percentage_change"]} to {quote["price"]}')
return alerts
Pair price moves with headlines from the Google News API in Python to see why a stock moved.
Limits to know
- Current quotes only. The endpoint returns the current quote. Build history by logging on a schedule, or use a market data provider for complete historical prices.
- Delays. Google Finance notes that quotes may be delayed depending on the exchange. Do not use it as a trading feed where exact real-time prices matter.
- Display formats. Prices are text as Google shows them, so parse them as shown above.
What it costs
Each quote or markets request uses one credit. PrismCrawl sells one-time packages from $5 for 16,667 requests ($0.30 per 1,000) to $1,000 for 6,666,667 ($0.15 per 1,000), with no subscription, and credits are valid for 90 days. See pricing.
For complete projects that combine prices with live news, see the news trading bot for stocks and crypto and the prediction market research bot.
Frequently asked questions
Is there a Google Finance API?
Not an official one. Google shut down its Google Finance API more than a decade ago. The GOOGLEFINANCE function in Google Sheets still works inside a spreadsheet, but it is not an API you can call from Python. To get Google Finance data in code, use a third-party API that returns the Google Finance page as JSON.
Can I get historical stock prices from Google Finance in Python?
PrismCrawl's Google Finance endpoint returns the current quote: price, price change, and percentage change. To build a history, log quotes on a schedule. For complete historical daily or intraday prices, use a dedicated market data provider.
Is Google Finance data real time?
Not always. Google Finance notes that quotes may be delayed depending on the exchange. It suits dashboards, research, alerts, and watchlists. For trading that depends on exact, real-time prices, use a licensed real-time market data feed.