Fix gspread APIError 429 with a 3-Layer Approach

Zusammenfassung

Pixel shares a practical guide to resolving gspread APIError 429 quota limits. It explains the 60-requests-per-minute per-user limit and shows how batching 5,000 rows into one update can replace thousands of requests, alongside smarter reads and exponential backoff.

DEV Community

gspread APIError 429: Quota exceeded for 'Write requests per minute per user' (and the 3-layer fix)

You loop over your data and write it to a Google Sheet, and after a few dozen calls: gspread.exceptions.APIError: APIError: [429]: Quota exceeded for quota metric
'Write requests' and limit 'Write requests per minute per user' of service 'sheets.googleapis.com'
A time.sleep(1) did not fix it, or it fixed it and now the job takes hours. This is what is going on. What Google counts Google's Sheets API usage limits page lists, for both reads and writes: 300 requests per minute per project and 60 requests per minute per user per project. Read and write each have their own bucket. A batchUpdate request counts as one request, however many operations it contains. Google's advice for a 429 is exponential backoff. (Limits change, so check the page.) Three consequences: The unit is the request, not the cell. One cell and one 60,000-cell block both cost one request. The binding limit for a script is usually the per-user one: 60 per minute. A service account counts as one user. It is a speed limit per minute, not a ban. Without retry code a throttled job simply crashes. The arithmetic Writing a 5,000-row, 12-column table: How you write it Requests Minimum time at 60/min update_cell in a double loop 60,000 about 1,000 minutes append_row in a loop 5,000 about 84 minutes one block with ws.update 1 under a minute Layer 1: make fewer requests (this fixes most 429s) import gspread

gc = gspread.service_account(filename="service_account.json")
ws = gc.open_by_key("YOUR_SHEET_ID").worksheet("Data")

rows = [["date", "usd"], ["2026-10-27", 1.115]] # your whole table as a list of lists
ws.update(values=rows, range_name="A1", value_input_option="USER_ENTERED") # one request
Note the argument order of gspread 6: values first, then the range. Also read once (ws.get_all_values()) and work in memory: every ws.cell() and ws.col_values() call is a request. To add rows below existing data in one request use ws.append_rows(rows, value_input_option="USER_ENTERED"). Layer 2: slow down on purpose A well-batched job can still exceed 60 a minute when it touches many tabs. Keep a small sliding window and sleep when you are about to go over (55 calls per 60 seconds leaves headroom under the documented 60). import time
from collections import deque

class PerMinuteLimiter:
def init(self, max_calls=55, window=60):
self.max_calls = max_calls
self.window = window
self.times = deque()

def wait(self):
    now = time.monotonic()
    while self.times and now - self.times[0] >= self.window:
        self.times.popleft()
    if len(self.times) >= self.max_calls:
        time.sleep(self.window - (now - self.times[0]))
        return self.wait()
    self.times.append(time.monotonic())

limiter = PerMinuteLimiter() # 55 calls per 60 seconds

before every Sheets call: limiter.wait()

Layer 3: retry politely, with backoff and jitter import random, time, gspread

def call_with_backoff(fn, args, tries=8, kwargs):
for n in range(tries):
try:
return fn(
args, **kwargs)
except gspread.exceptions.APIError as e:
if e.code not in (429, 500, 502, 503, 504) or n == tries - 1:
raise # not retryable, or out of attempts
time.sleep(min(2 ** n + random.random(), 64))

limiter.wait()
call_with_backoff(ws.update, values=rows, range_name="A1", value_input_option="USER_ENTERED")
Two details that matter: Retry only what is worth retrying. A 403 "permission denied" or a 404 will never fix itself; retrying hides the real problem. e.code comes from the JSON error body; for a normal Sheets 429 it is the integer 429. Wait longer than one quota window. A per-minute quota needs about a minute to recover. In my own test with one Cloud project, writes became possible again between under 10 and about 130 seconds after a burst (usually 40 to 60; about eight trials). A version that gave up after six retries (about 66 seconds in...
Fix gspread APIError 429 with a 3-Layer Approach
Powered by Readybot.io

Das Neueste von Pixel

Incident Response: Look Beyond the Red Alert

Pixel’s DEV Community announcement explores how teams can fixate on one failing service while overlooking the real cause of an outage, such as a full …

Sach: AI Fact-Checks WhatsApp Forwards in India

Pixel’s announcement introduces Sach, a tool that checks forwarded messages in English, Hindi, Telugu, and 14 other Indian languages against official sources. It gives cited …

Java 25 Removes SecurityManager: What to Fix

Pixel’s announcement explains how Java 24’s JEP 486 permanently disabled the SecurityManager, breaking test workarounds that intercept System.exit. It recommends returning exit codes or throwing …