Migrating from google-search-results
SerpApi has two Python libraries that use similar import names. For new projects and active integrations, use the recommended serpapi package.
Recommended Package
The new and recommended client is serpapi on PyPI.
Install it with:
pip install serpapiUse serpapi.Client:
import os
import serpapi
YOUR_API_KEY = os.environ["SERPAPI_KEY"]
client = serpapi.Client(api_key=YOUR_API_KEY)
results = client.search(engine="google", q="coffee")
print(results)This is the package used throughout the current documentation.
Deprecated Package
The old Python SDK is google-search-results on PyPI. It is deprecated for new integrations.
It was installed with:
pip install google-search-resultsOlder code often looks like this:
from serpapi import GoogleSearch
search = GoogleSearch({
"q": "coffee",
"location": "Austin,Texas",
"api_key": "<your secret api key>",
})
result = search.get_dict()Do not add this package to new projects.
Update Your Dependencies
Remove google-search-results from your dependency files, such as requirements.txt, pyproject.toml, setup.py, Pipfile, or Poetry dependency configuration.
Then add serpapi instead:
pip install serpapiAvoid installing both packages in the same environment. They can share the serpapi import namespace, which makes migration harder to reason about.
Update Your Code
Replace GoogleSearch(...).get_dict() with serpapi.Client(...).search(...).
Old:
from serpapi import GoogleSearch
search = GoogleSearch({
"q": "coffee",
"location": "Austin,Texas",
"api_key": "<your secret api key>",
})
result = search.get_dict()New:
import os
import serpapi
client = serpapi.Client(api_key=os.environ["SERPAPI_KEY"])
results = client.search(
engine="google",
q="coffee",
location="Austin, Texas",
)Search parameters use the same SerpApi names, so most request parameter usage can move over directly. Prefer passing them as keyword arguments in new code; dictionaries are still accepted when migration code already has parameters in a mapping.
Migration Checklist
- Remove
google-search-resultsfrom requirements and dependency files. - Install
serpapiwithpip install serpapi. - Replace
from serpapi import GoogleSearchwithimport serpapi. - Replace
GoogleSearch(params).get_dict()withserpapi.Client(api_key=...).search(engine=..., q=..., ...). - Keep using the SerpApi Playground and the SerpApi API documentation to confirm engine parameters.