{"id":5819,"library":"serpapi","title":"SerpApi Python Client","description":"The official Python client for SerpApi.com, allowing users to access structured search results from various engines like Google, Bing, Baidu, and more. Currently at version 1.0.2, the library is actively maintained with frequent updates and bug fixes, reflecting continuous development and responsiveness to API changes.","status":"active","version":"1.0.2","language":"en","source_language":"en","source_url":"https://github.com/serpapi/serpapi-python","tags":["api-client","search","serp","google","bing","baidu"],"install":[{"cmd":"pip install serpapi","lang":"bash","label":"Install SerpApi"}],"dependencies":[],"imports":[{"symbol":"Client","correct":"from serpapi import Client"},{"note":"The `GoogleSearch` class is part of the legacy `google-search-results` package (also sometimes imported as `serpapi`), not the current `serpapi` client library. Use `serpapi.Client` instead for the recommended package.","wrong":"from serpapi import GoogleSearch","symbol":"GoogleSearch","correct":"from google_search_results import GoogleSearch"}],"quickstart":{"code":"import os\nfrom serpapi import Client\n\n# Ensure SERPAPI_KEY is set as an environment variable\n# Example (bash): export SERPAPI_KEY='your_private_api_key'\napi_key = os.environ.get('SERPAPI_KEY', '')\n\nif not api_key:\n    print(\"Error: SERPAPI_KEY environment variable not set.\")\nelse:\n    client = Client(api_key=api_key)\n    try:\n        results = client.search({\n            \"engine\": \"google\",\n            \"q\": \"Coffee\",\n            \"location\": \"Austin, Texas, United States\",\n            \"hl\": \"en\",\n            \"gl\": \"us\"\n        })\n        print(results.get(\"organic_results\", [])[0].get(\"title\"))\n    except Exception as e:\n        print(f\"An error occurred: {e}\")","lang":"python","description":"This example demonstrates how to perform a Google search using the `serpapi.Client`. It fetches results for 'Coffee' in Austin, Texas, and prints the title of the first organic result. The API key is securely retrieved from an environment variable."},"warnings":[{"fix":"Migrate your import and usage pattern. Replace `from serpapi import GoogleSearch` with `from serpapi import Client` and instantiate `Client(api_key=...)` directly, then use `client.search(...)`.","message":"The `serpapi` package (current official client) is distinct from the older `google-search-results` package, which sometimes used `from serpapi import GoogleSearch`. Code written for the legacy package will not work directly with the new `serpapi` client.","severity":"breaking","affected_versions":"All versions >= 1.0.0 of `serpapi` when migrating from `google-search-results`."},{"fix":"Always set your `SERPAPI_KEY` as an environment variable (e.g., `export SERPAPI_KEY='your_key'`) and access it via `os.environ.get('SERPAPI_KEY')` or pass it directly when initializing `Client(api_key='your_key')`. Avoid hardcoding in source control.","message":"Incorrect API key handling (hardcoding or not setting environment variable) is a common cause of `Unauthorized` (401) or `Bad Request` (400) errors.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Review code interacting with Google search parameters and pagination logic if upgrading from versions prior to 1.0.0. The `engine` parameter may still be specified but its internal handling or default behavior changed. Ensure pagination starts at the correct point if `yield_pages` is used.","message":"Version 1.0.0 removed the 'redundant engine' parameter for Google searches and changed `yield_pages` to start from the first page, potentially altering expected behavior or requiring adjustments for pagination logic.","severity":"breaking","affected_versions":"< 1.0.0"},{"fix":"Upgrade to `serpapi` version 1.0.0 or higher to ensure `serpapi.HTTPError` provides full details, including `status_code` and `message`, for more robust error handling.","message":"Prior to v1.0.0, `serpapi.HTTPError` instances might have been missing essential status code and error messages, making debugging API request failures difficult.","severity":"gotcha","affected_versions":"< 1.0.0"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}