SerpApi Python Library & Package
serpapi is the official Python client for SerpApi. Use it to search the web and read the results in your Python programs.
SerpApi supports Google, Google Maps, Google Shopping, Bing, DuckDuckGo, Baidu, Yandex, Yahoo, eBay, YouTube, App Stores, Walmart, Home Depot, Naver, and many more engines.
You can retrieve web search results, local business listings, shopping results, flight schedules, stock market data, job listings, trends, news headlines, AI Overview answers, and video search results.
Install
Run one of these commands in your terminal. Use pip to install into your Python environment, or uv add if you manage your project with uv.
pip install serpapi
uv add serpapi
The package requires Python 3.6 or newer.
First Request
Sign up at SerpApi and copy your API key from the dashboard. Replace secret_api_key below with your key, then run the command in your terminal. On Windows, use PowerShell.
export SERPAPI_KEY="secret_api_key"
$env:SERPAPI_KEY = "secret_api_key"
Run this code in a Python script or interpreter started from the same terminal so it can read SERPAPI_KEY:
import os
import serpapi
client = serpapi.Client(api_key=os.environ["SERPAPI_KEY"])
results = client.search(
engine="google",
q="coffee",
location="Austin, Texas",
hl="en",
gl="us",
)
print(results["organic_results"][0]["link"])
This prints the link from the first organic result, which is an unpaid search listing. results["organic_results"] is a list, and [0] selects its first item. See Getting Started for setup instructions and an explanation of each parameter.
The results variable contains a SerpResults object. You can read its fields like a Python dictionary, convert it to a plain dictionary, or use its methods to fetch more pages. You can also retrieve saved searches with client.search_archive().
Use the same search parameter names as the SerpApi API documentation. The SerpApi Playground lets you try a search in your browser and copy its parameters into Python.
Documentation Map
Getting Started covers installation and your first search. Client Usage explains how to make requests and read responses.
AI Agents covers search tools, Markdown results, and API references for agents.
Output Formats explains when to use JSON, Markdown, or HTML.
Extract API covers page content in Markdown or JSON, URL discovery, and crawling.
Migration Guide shows how to replace
google-search-resultswith this package.Parameters and Engines explains search parameters and how to test them in the SerpApi Playground.
For scripts that collect results, see pagination, timeouts and errors, request options, and account and locations.
For searches you retrieve later, selected response fields, and data retention settings, see Async Search Archive, JSON Restrictor, and Zero Trace.
Examples includes searches for web pages, AI answers, local businesses, products, travel, finance, trends, jobs, media, apps, and research.