API Reference
Look up the arguments, return values, and exceptions for the functions and classes in serpapi. For examples of how to use them together, see Client Usage.
- exception serpapi.APIKeyNotProvided
API key is not provided.
- exception serpapi.HTTPConnectionError(original_exception)
Connection Error.
- exception serpapi.HTTPError(original_exception)
HTTP Error.
- exception serpapi.SearchIDNotProvided
Search ID is not provided.
- exception serpapi.SerpApiError
Base class for exceptions in this module.
- exception serpapi.TimeoutError(*args: Any, **kwargs: Any)
Timeout Error.
- class serpapi.Client(*, api_key=None, timeout=None)
A class that handles API requests to SerpApi in a user-friendly manner.
Store your API key in an environment variable, then create a client with
serpapi.Client(api_key=os.environ["SERPAPI_KEY"]).- Parameters:
api_key – The API Key to use for SerpApi.com.
timeout – The default timeout to use for requests.
- account(params: dict = None, **kwargs)
Get SerpApi account information.
- Parameters:
params – Account API parameters.
kwargs – Additional account parameters or request options.
timeout,proxies,verify,stream, andcertare passed to the underlying HTTP request.
Learn more: https://serpapi.com/account-api
- locations(params: dict = None, **kwargs)
Get a list of supported Google locations.
- Parameters:
params – Location API parameters such as
qandlimit.kwargs – Additional location parameters or request options.
timeout,proxies,verify,stream, andcertare passed to the underlying HTTP request.
Learn more: https://serpapi.com/locations-api
- search(params: dict = None, **kwargs)
Fetch a page of results from SerpApi.
Returns a
serpapi.SerpResultsobject for JSON responses, or text whenoutput="html"oroutput="md"is requested. Prefer passing SerpApi engine parameters as keyword arguments. A parameter dictionary is also accepted when your code already has parameters in a mapping.- Parameters:
params – Optional mapping of SerpApi search parameters such as
engine,q,location, andoutput.kwargs – Additional SerpApi parameters or request options.
timeout,proxies,verify,stream, andcertare passed to the underlying HTTP request.
Learn more: https://serpapi.com/search-api
- search_archive(params: dict = None, **kwargs)
Get a result from the SerpApi Search Archive API.
- Parameters:
params – Archive parameters. Must include
search_id.outputacceptsjson(default),html, ormd.kwargs – Additional archive parameters or request options.
timeout,proxies,verify,stream, andcertare passed to the underlying HTTP request.
Learn more: https://serpapi.com/search-archive-api
- upload_image(image, **kwargs)
Upload an image to SerpApi’s Image API.
imagecan be a filesystem path or an open binary file object. The returned dictionary contains animage_idthat can be passed tosearch()for engines that accept uploaded images, such as Google Lens.- Parameters:
image – a path or open binary file object containing a JPG/JPEG, PNG, or WebP image no larger than 500 KB.
api_key – the API Key to use for SerpApi.com.
** – any additional multipart form fields to pass to the API.
Learn more: https://serpapi.com/image-api
- class serpapi.SerpResults(data, *, client)
A dictionary-like object that represents the results of a SerpApi request.
An instance of this class is returned if the response is a valid JSON object. It can be used like a dictionary, but also has some additional methods.
- as_dict()
Returns the data as a standard Python dictionary.
This can be useful when passing results to libraries that expect a plain
dict.
- next_page()
Return the next page of results, if any.
- yield_pages(max_pages=1000)
A generator that
yields the nextnpages of search results, if any.- Parameters:
max_pages – limit the number of pages yielded to
n.
- property next_page_url
The URL of the next page of results, if any.
- serpapi.account(params: dict = None, **kwargs)
Get SerpApi account information.
- Parameters:
params – Account API parameters.
kwargs – Additional account parameters or request options.
timeout,proxies,verify,stream, andcertare passed to the underlying HTTP request.
Learn more: https://serpapi.com/account-api
- serpapi.locations(params: dict = None, **kwargs)
Get a list of supported Google locations.
- Parameters:
params – Location API parameters such as
qandlimit.kwargs – Additional location parameters or request options.
timeout,proxies,verify,stream, andcertare passed to the underlying HTTP request.
Learn more: https://serpapi.com/locations-api
- serpapi.search(params: dict = None, **kwargs)
Fetch a page of results from SerpApi.
Returns a
serpapi.SerpResultsobject for JSON responses, or text whenoutput="html"oroutput="md"is requested. Prefer passing SerpApi engine parameters as keyword arguments. A parameter dictionary is also accepted when your code already has parameters in a mapping.- Parameters:
params – Optional mapping of SerpApi search parameters such as
engine,q,location, andoutput.kwargs – Additional SerpApi parameters or request options.
timeout,proxies,verify,stream, andcertare passed to the underlying HTTP request.
Learn more: https://serpapi.com/search-api
- serpapi.search_archive(params: dict = None, **kwargs)
Get a result from the SerpApi Search Archive API.
- Parameters:
params – Archive parameters. Must include
search_id.outputacceptsjson(default),html, ormd.kwargs – Additional archive parameters or request options.
timeout,proxies,verify,stream, andcertare passed to the underlying HTTP request.
Learn more: https://serpapi.com/search-archive-api
- serpapi.upload_image(image, **kwargs)
Upload an image to SerpApi’s Image API.
imagecan be a filesystem path or an open binary file object. The returned dictionary contains animage_idthat can be passed tosearch()for engines that accept uploaded images, such as Google Lens.- Parameters:
image – a path or open binary file object containing a JPG/JPEG, PNG, or WebP image no larger than 500 KB.
api_key – the API Key to use for SerpApi.com.
** – any additional multipart form fields to pass to the API.
Learn more: https://serpapi.com/image-api