← Back to blog

Google Search API in Python: Complete Tutorial (2026)

Google Search API in Python tutorial: requests examples, retries, pagination, a reusable client — and 100 free searches to test with.

1 min read

This tutorial shows how to query Google from Python and get clean, structured results — using serp.cheap, the cheapest Google Search API in 2026.

Install

pip install requests
export SERP_CHEAP_API_KEY="your-key"

The endpoint itself is one POST — here it is as curl, so you know what the Python code below is actually doing:

curl -s https://api.serp.cheap/v1/search \
  -H "X-API-Key: $SERP_CHEAP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"q": "best electric cars 2026", "gl": "us"}'

Minimal example

import os
import requests

API_KEY = os.environ["SERP_CHEAP_API_KEY"]

resp = requests.post(
    "https://api.serp.cheap/v1/search",
    headers={"X-API-Key": API_KEY},
    json={"q": "best electric cars 2026", "gl": "us", "page": 1},
    timeout=30,
)
resp.raise_for_status()
for r in resp.json()["organic"]:
    print(f'#{r["position"]} {r["title"]} — {r["link"]}')

Output:

$ python search.py
#1 Best Electric Cars of 2026 — https://www.example.com/best-electric-cars-2026
#2 Electric Cars: Every EV You Can Buy in 2026 — https://www.example-autos.com/ev-buyers-guide
#3 Top-Rated EVs Compared — https://www.example-reviews.org/evs/top-rated
#4 Electric vehicle — Wikipedia — https://en.wikipedia.org/wiki/Electric_vehicle
#5 2026 EV Range and Price Comparison — https://www.example.com/ev-comparison
...

A reusable client with retries

import os
import requests
from requests.adapters import HTTPAdapter, Retry

class SerpClient:
    def __init__(self, api_key: str):
        self.s = requests.Session()
        self.s.headers.update({"X-API-Key": api_key})
        retries = Retry(total=4, backoff_factor=1.5,
                        status_forcelist=[429, 500, 502, 503, 504],
                        allowed_methods=["POST"])  # Retry skips POST by default
        self.s.mount("https://", HTTPAdapter(max_retries=retries))

    def search(self, q, gl="us", page=1, tbs=None):
        body = {"q": q, "gl": gl, "page": page}
        if tbs:
            body["tbs"] = tbs
        r = self.s.post("https://api.serp.cheap/v1/search", json=body, timeout=30)
        r.raise_for_status()
        return r.json()

client = SerpClient(os.environ["SERP_CHEAP_API_KEY"])
data = client.search("python web scraping", gl="us")
print(data["stats"])  # balance, cost, cached

Paginate

def all_results(client, q, pages=3, gl="us"):
    """Fetch up to `pages` pages and return one flat list of organic results."""
    results = []
    for p in range(1, pages + 1):
        organic = client.search(q, gl=gl, page=p).get("organic", [])
        if not organic:
            break  # no more results — stop paying for empty pages
        results.extend(organic)
    return results

top30 = all_results(client, "python web scraping", pages=3)
print(len(top30), "results")

Each page is a separate billed request — fetch lazily. More in pagination.

Cost control

stats.cost is in credits (1 = $0.0001). Cache hits cost 3 credits, fresh 6. Repeated queries are served from cache automatically at half price.

Next

Try serp.cheap

Every snippet in this tutorial runs as-is once you export your API key. 100 free searches on signup — no card required; pay-as-you-go from $0.75/1k after that, and credits stay valid for 12 months.

Frequently asked questions

What's the easiest way to call a Google Search API in Python?+

Use the requests library to POST your query to a SERP API. With serp.cheap: requests.post('https://api.serp.cheap/v1/search', headers={'X-API-Key': KEY}, json={'q': query, 'gl': 'us'}). The response JSON has an organic[] list. Prefer a typed client? Install the official SDK with pip install serpcheap (Django and FastAPI integrations are available too).

How do I handle rate limits in Python?+

Catch HTTP 429 and retry with exponential backoff (e.g. via urllib3 Retry or tenacity). serp.cheap's free tier allows 60 requests/minute (1 req/s); pay-as-you-go is 600/minute (10 req/s), up to 60 req/s on top plans.

Get your API key

Cheapest direct, pay by card or crypto, no KYC. Or use a marketplace.