- Notifications
You must be signed in to change notification settings - Fork9
a Python client library for SerpApi.
License
NotificationsYou must be signed in to change notification settings
serpapi/serpapi-python
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Official Python client for SerpApi.com - Search Engine Results API.
- Async/await support for non-blocking HTTP requests
- Persistent connections for 2x faster response times
- Multiple search engines (Google, Bing, Yahoo, Baidu, Yandex, etc.)
- Comprehensive API coverage (Search, Location, Account, Search Archive)
- Type hints and extensive documentation
# Using pippip install serpapi# Using uv (recommended)uv add serpapi
importasynciofromserpapiimportClientasyncdefmain():client=Client(api_key="your_api_key",engine="google")results=awaitclient.search({"q":"coffee"})forresultinresults.get("organic_results", []):print(f"Title:{result.get('title')}")print(f"Link:{result.get('link')}")awaitclient.close()asyncio.run(main())
Get your API key fromserpapi.com/signup.
Set environment variable:
export SERPAPI_KEY="your_secret_key"
This library is well documented, and you can find the following resources:
- Full documentation on SerpApi.com
- Library Github page
- Library GEM page
- Library API documentation
- API health status
results=awaitclient.search({"q":"coffee"})print(f"Found{len(results.get('organic_results', []))} organic results")
html_content=awaitclient.html({"q":"coffee"})print(f"HTML content length:{len(html_content)} characters")
locations=awaitclient.location({"q":"Austin","limit":3})print(f"Found{len(locations)} locations")
archived=awaitclient.search_archive(search_id)print(f"Retrieved archived search:{archived.get('search_metadata', {}).get('id')}")
account=awaitclient.account()print(f"Account plan:{account.get('plan')}")
importasyncioasyncdefsearch_company(client,company):results=awaitclient.search({"q":company})return {"company":company,"count":len(results.get("organic_results", []))}asyncdefmain():client=Client(api_key="your_api_key",persistent=True)companies= ["meta","amazon","apple","netflix","google"]tasks= [search_company(client,company)forcompanyincompanies]results=awaitasyncio.gather(*tasks)forresultinresults:print(f"{result['company']}:{result['count']} results")awaitclient.close()asyncio.run(main())
asyncwithClient(api_key="your_api_key")asclient:results=awaitclient.search({"q":"coffee"})# Client automatically closed
fromserpapiimportSerpApiErrortry:results=awaitclient.search({"q":"coffee"})exceptSerpApiErrorase:print(f"SerpApi error:{e}")
The UV Package Manager must be installed. Seeuv installation instructions.
The following commands are available:
# Install dependencies (including formatting tools)uv sync --dev# Run testsuv run pytest# Run test with coverageuv run pytest --cov=serpapi tests/# Type checking with mypyuv run mypy serpapi/# Format code with blackuv run black serpapi/# Sort imports with isortuv run isort serpapi/# Check formatting without making changesuv run black --check.uv run isort --check-only.
- Fast: 10-100x faster than pip
- Reliable: Lock file ensures reproducible builds
- Simple: Single command for most operations
- Modern: Built for Python 3.11+ with async support
serpapi-python/├── .python-version # Python version (3.11)├── uv.lock # Dependency lock file├── .venv/ # Virtual environment (auto-created)├── pyproject.toml # Project configuration├── serpapi/ # Package source code├── tests/ # Test suite├── examples/ # Usage examples└── README.md # This fileMIT License - see LICENSE file for details.
About
a Python client library for SerpApi.
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.