Getting Started

The serpapi package lets you request search results from SerpApi in Python. You need Python installed and a SerpApi account with an API key.

Installation

Run one of these commands in your terminal. Use pip for an existing Python environment, uv add for a uv project, or uv pip install for a virtual environment managed with uv.

pip install serpapi
uv add serpapi
uv pip install serpapi

The package requires Python 3.6 or newer.

Create or sign in to your SerpApi account and copy your API key from the dashboard. An API key identifies your account when you make a request. Replace secret_api_key below with your key and run the command in your terminal. On Windows, use PowerShell.

export SERPAPI_KEY="secret_api_key"
$env:SERPAPI_KEY = "secret_api_key"

What the Parameters Mean

The example above sends a Google Search request:

Parameter

Purpose

engine

Selects the SerpApi engine. google is Google Search.

q

Text to search for, such as coffee shops.

location

Location to search from, such as Austin, Texas.

hl

Language for the Google interface. en is English.

gl

Country for Google results. us is the United States.

Each engine has its own search parameters, listed in the SerpApi API documentation. Use the SerpApi Playground to try a search in your browser and copy the parameters into Python.

When to Use the Client

Create a serpapi.Client when you need to make several requests, fetch more pages, or run searches at the same time. You can reuse its API key, timeout, and HTTP session, which manages connections to SerpApi.

For a single search, you can also call serpapi.search() directly:

import serpapi

results = serpapi.search(
    api_key="secret_api_key",
    engine="google",
    q="coffee",
)

To reuse the same settings for later searches, create a client:

client = serpapi.Client(api_key="secret_api_key", timeout=20)
results = client.search(engine="google", q="coffee")

Next Steps