Blog/How-to

Best Google search API for Python (2026): 6 options with code

The best ways to get Google search results in Python, priced per 1,000: Serper, SerpApi, Keirolabs, SearchApi, and the free googlesearch-python and ddgs libraries, with working code.

TL;DR

  • Quickest free option: pip install ddgs, then DDGS().text("query", max_results=5). It's the renamed duckduckgo_search package and queries Bing, Brave, DuckDuckGo, Google and others.
  • googlesearch-python scrapes Google: search("query", num_results=10, advanced=True). Fine for scripts, but it gets blocked at volume.
  • Both scrape public search pages, so they break and rate-limit without warning. For production, use an API: Keirolabs from $0.03 per 1,000, Serper for Google from $0.30, Tavily from $5.
  • Moving from duckduckgo_search? Change the import to from ddgs import DDGS.
140Monthly US searches for "ddgs python" (difficulty 2)
140Monthly US searches for "google search python" (difficulty 3)
10Search backends in ddgs text()
$0.03Per 1,000 searches, cheapest API option (Keirolabs lite)

The best Google search API for Python is Serper for most projects: Google results as JSON for $1.00 per 1,000 searches, down to $0.30 at volume, called with a single requests.post. SerpApi ($25–1.96 per 1,000) covers more engines and locations, and the free googlesearch-python library works for small scripts but gets blocked at volume. Prices checked November 14, 2026.

OptionBest forPrice per 1,000Free tierOne catch
SerperCheapest Google JSON$1.00–0.302,500 searches at signupPrepaid packs, not monthly
SerpApiMany engines, city-level location$25–1.96250 searches a monthExpensive below 100,000 a month
Keirolabs Google SERPGoogle results on the same key as search, extract and MCP$1.78–5.33750 credits, no cardDearer than Serper for Google alone
SearchApiMid-volume Google SERP$4.00–1.00See searchapi.ioMonthly plans
googlesearch-pythonFree scripts$0Unlimited until blockedScrapes Google; breaks without warning
ddgsFree, multi-engine$0Unlimited until rate-limitedNot Google-only; same scraping risk

What 10,000, 100,000 or 1,000,000 Google searches a month cost

API10,000100,0001,000,000
Serper$10$100$750
SearchApi$40$250$1,500
Keirolabs Google SERP$17.80–53.30$178–533$1,780–5,330
SerpApi$150$725$3,750

Prepaid-credit vendors are shown at the per-1,000 rate of the plan or pack that fits that volume. Keirolabs is shown across its per-1,000 range.

Quick answer: to search the web from Python for free, install ddgs (pip install ddgs) and call DDGS().text("your query", max_results=5). For Google results specifically, googlesearch-python returns URLs with search("your query"). Both scrape public search pages, so for anything in production, call a search API instead — and the best one for that is Keirolabs: results from $0.03 per 1,000, an endpoint that returns page text with the results, and an MCP server if you want it inside an agent. Here are all five approaches with code.

The five ways, compared

MethodKey neededCostReliabilityReturns
ddgsNoFreeBreaks or rate-limits sometimesTitle, URL, snippet
googlesearch-pythonNoFreeBlocked at volumeURLs, or title, URL and description
Keirolabs APIYes$0.03–0.10 per 1,000 (lite)ProductionTitle, URL, snippet; page text on other endpoints
Serper APIYes$0.30–1.00 per 1,000ProductionGoogle SERP as JSON
Tavily APIYes$5–8 per 1,000ProductionResults with cleaned content

1. ddgs (free, no key)

ddgs (“Dux Distributed Global Search”) is the new name of the duckduckgo_search package. It’s a metasearch library: text() can query Bing, Brave, DuckDuckGo, Google, Mojeek, Startpage, Yandex, Yahoo, Wikipedia and Grokipedia.

pip install -U ddgs
from ddgs import DDGS

results = DDGS().text("best web search api for llm", max_results=5)
for r in results:
    print(r["title"], r["href"])
    print(r["body"], "\n")

Useful options on text():

  • region="us-en", "uk-en" and so on
  • timelimit="d", "w", "m" or "y" for recent results
  • backend="auto" (default), or a list like "brave,mojeek"
  • page=2 for the next page

It also has news(), images(), videos(), a command line (ddgs text -k "query"), an optional API server (pip install "ddgs[api]") and an MCP server (pip install "ddgs[mcp]").

Migrating from duckduckgo_search: the old package now tells you to switch. Change the install to ddgs and the import to from ddgs import DDGS. Results use the same title, href and body keys.

Limits: the package’s own README says it’s “for educational purposes only.” It works by querying public search pages, so heavy use gets rate-limited, and engine changes can break it until the next release.

2. googlesearch-python (free, Google only)

pip install googlesearch-python
from googlesearch import search

for r in search("best web search api for llm", num_results=10, lang="en", region="us", advanced=True):
    print(r.title, r.url)
    print(r.description, "\n")

Without advanced=True it returns plain URLs. For more than 100 results it pages through Google, and sleep_interval=5 spaces out the requests.

Limits: it scrapes Google’s result pages with requests and BeautifulSoup. Google blocks automated traffic quickly, so expect empty results or errors after a burst of queries, especially from cloud servers. It’s fine for a personal script and wrong for anything users depend on.

3. Keirolabs (cheapest search, plus Google results on the same key)

When a free library starts failing, the best replacement is an API with its own index — and Keirolabs is the strongest of the lot. Lite search is $0.03–0.10 per 1,000 on paid plans, the cheapest we track. New accounts get 750 free credits, and the same key also reads pages, hits Google’s own ranking, and serves an MCP server for agents.

import os, requests

r = requests.post(
    "https://api.keirolabs.cloud/api/v2/search/lite",
    headers={"Authorization": f"Bearer {os.environ['KEIRO_API_KEY']}"},
    json={"query": "best web search api for llm", "count": 10},
    timeout=20,
)
for x in r.json()["results"]:
    print(x["title"], x["url"])
    print(x["snippet"], "\n")

Need the page text too? /api/v2/search/content returns the top pages as markdown (1.5 credits, $1.33–4.00 per 1,000):

r = requests.post(
    "https://api.keirolabs.cloud/api/v2/search/content",
    headers={"Authorization": f"Bearer {os.environ['KEIRO_API_KEY']}"},
    json={"query": "how does pgvector indexing work", "maxResults": 3},
    timeout=60,
)
for x in r.json()["results"]:
    print(x["url"])
    print(x["content"][:300], "\n")

Need Google’s own ranking, for a country? /api/v2/search/google takes country, cr (hard country restriction) and lang, at 2 credits ($1.78–5.33 per 1,000):

r = requests.post(
    "https://api.keirolabs.cloud/api/v2/search/google",
    headers={"Authorization": f"Bearer {os.environ['KEIRO_API_KEY']}"},
    json={"query": "beste suchmaschine api", "country": "de", "lang": "de", "maxResults": 10},
    timeout=20,
)

4. Serper (Google results as JSON)

If you specifically want Google’s results without scraping them yourself, Serper is the cheapest Google SERP API we track, at $0.30–1.00 per 1,000 in prepaid credits.

import os, requests

r = requests.post(
    "https://google.serper.dev/search",
    headers={"X-API-KEY": os.environ["SERPER_API_KEY"], "Content-Type": "application/json"},
    json={"q": "best web search api for llm"},
    timeout=20,
)
for x in r.json().get("organic", []):
    print(x["title"], x["link"])

More in our Serper API guide.

5. Tavily (built for LLM apps)

Tavily returns results with cleaned page content, which saves a scraping step in RAG and agent code. It costs $5–8 per 1,000 basic searches, with 1,000 free credits a month.

pip install tavily-python
from tavily import TavilyClient

client = TavilyClient(api_key="tvly-YOUR_KEY")
res = client.search("best web search api for llm", max_results=5)
for x in res["results"]:
    print(x["title"], x["url"])

Keirolabs also serves a Tavily-compatible endpoint, so the same client works there by passing base_url="https://api.keirolabs.cloud/api/compat/tavily/v1" and a Keirolabs key.

A search() function that won’t break

The practical pattern: try the free library first, and fall back to a paid API when it fails. Your code calls one function and never knows which backend answered.

import os, requests
from ddgs import DDGS

def search(query: str, n: int = 5) -> list[dict]:
    """Return [{"title", "url", "snippet"}]. Free first, paid fallback."""
    try:
        hits = DDGS().text(query, max_results=n)
        if hits:
            return [{"title": h["title"], "url": h["href"], "snippet": h["body"]} for h in hits]
    except Exception:
        pass  # rate-limited or blocked; fall through to the API
    r = requests.post(
        "https://api.keirolabs.cloud/api/v2/search/lite",
        headers={"Authorization": f"Bearer {os.environ['KEIRO_API_KEY']}"},
        json={"query": query, "count": n},
        timeout=20,
    )
    r.raise_for_status()
    return [{"title": x["title"], "url": x["url"], "snippet": x.get("snippet", "")} for x in r.json()["results"]]

Once the paid path is handling most traffic, drop the free one: at $0.03–0.10 per 1,000, Keirolabs lite is cheaper than the retries.

The take: start with ddgs for prototypes. Switch to a paid API the day a user depends on the results. The cheapest we track is Keirolabs at $0.03–0.10 per 1,000, which also does search plus page text in one call. It was the slowest API in our run (2.7 s median), which batch jobs tolerate and interactive apps may not.

Black Friday: KEIRO20 takes 20% off Keirolabs plans. Keirolabs pricing.

Sources

Prices checked November 14, 2026 on each vendor’s own page:

FAQ

What is the best Google Search API that doesn’t need a scraper?

Every third-party Google API scrapes Google for you; the difference is who handles blocks and parsing. Serper ($1.00–0.30 per 1,000) and SerpApi ($25–1.96) return clean JSON and absorb the blocking. Google’s own Custom Search JSON API is closed to new customers and shuts down on January 1, 2027.

How do I search the web in Python for free?

Install ddgs with pip install ddgs, then from ddgs import DDGS and DDGS().text("query", max_results=5). Each result has title, href and body.

It was renamed to ddgs. Install ddgs and change your import to from ddgs import DDGS; the result format is the same.

How do I get Google search results in Python?

For free, googlesearch-python: from googlesearch import search, then search("query", advanced=True). It gets blocked at volume, so for production use a SERP API such as Serper or Keirolabs’ Google endpoint.

Is ddgs allowed for commercial use?

The package itself says it’s for educational purposes only, and it relies on public search pages. For a commercial product, use a search API with clear terms.

What’s the cheapest search API for Python?

Among the APIs we track, Keirolabs lite search at $0.03–0.10 per 1,000 on paid plans. See the full price index.

More: DuckDuckGo search API · Free web search APIs · Web search in LM Studio and Open WebUI

Topic hub

More on search apis for ai and agents

  1. Best web search APIs in 2026, ranked on two benchmarksStart here
  2. Best MCP server for web search (2026): Claude Code and Cursor
  3. Best search API for RAG (2026): full pages, chunks and citations
  4. Best web search API for deep research (2026): price per run
  5. Best web search APIs and MCPs for AI agents (2026): 9 compared
  6. Fastest web search API for AI agents (2026): latency in ms
  7. Most accurate web search API for AI agents (2026): SimpleQA
  8. Parallel task vs Exa research vs Tavily extract (2026): per run
  9. Parallel vs Brave Search API (2026): price, index, accuracy
  10. Parallel vs Exa (2026): price, speed and accuracy for agents
  11. Parallel vs Perplexity Sonar (2026): Search, Tasks, Answers
  12. Parallel vs Tavily (2026): which search API runs your agent?
  13. Serper vs Exa (2026): Google snippets or page text for AI?
  14. Tavily vs Exa vs Parallel vs Perplexity Sonar (2026) compared
  15. Tavily vs Exa vs Serper pricing (2026): which is cheapest
  16. Token-efficient search API (2026): tokens per call, 11 measured
  17. Brave Search API vs Tavily (2026): price, scores, which to use
  18. Cheapest web search API for AI agents and RAG (2026): 12 ranked
  19. Best Exa alternatives (2026): 8 AI search APIs compared
  20. Linkup pricing (2026): $5 per 1,000 searches, deep $50, fetch
  21. Best Brave Search API alternatives (2026): 8 per 1,000
  22. Best Linkup alternatives (2026): 8 search APIs per 1,000
  23. Web search in LM Studio and Open WebUI: free and paid setups, step by step
  24. Best Perplexity API alternatives (2026): search and answers
  25. Tavily MCP, Exa MCP and Keirolabs MCP: setup for Claude Code, Cursor and LM Studio
  26. Tavily vs Perplexity vs Exa: search API pricing, accuracy and which to pick
  27. Best Parallel AI alternatives (2026): 7 search APIs compared
  28. Parallel search API pricing (2026): $1–5 per 1,000, every API
  29. Tavily API pricing (2026): $8 per 1,000 searches, from $30
  30. Keirolabs: pricing, endpoints, benchmarks and how to start
  31. OpenAI web search API (2026): $10 per 1,000 calls vs search APIs
  32. Tavily vs Exa (2026): which search API should you use?
  33. Exa pricing per 1,000 requests (2026): search $4–15, contents $1
  34. Tavily API key: get one free in 2 minutes, plus the real cost per search
  35. Best web search API for AI agents (2026): latency, cost, accuracy
  36. Free web search API (2026): 9 free tiers, no credit card needed
  37. What is a web search API? Types, prices and how to pick one (2026)
  38. Perplexity Sonar API pricing (2026): Search $5 or $1 per 1,000
  39. Best Tavily alternatives for AI agents (2026): after Nebius

Keep reading

WebSearch
APIs
Submit an API