Skip to main content

Official Python SDK for SerpShot API - Google Search Results

Project description

SerpShot Python SDK

Official Python client for the SerpShot API - Get real-time Google search results programmatically.

Python Version License

中文文档 | English

Key Features

  • Lightning Fast - Get results in 1-2 seconds with optimized infrastructure
  • 🌍 Global Coverage - Support for 200+ countries and regions
  • 🔒 Reliable & Secure - 99.9% uptime SLA with enterprise-grade security
  • 🚀 Developer Friendly - Sync/async support, full type hints, intuitive API
  • 🔄 Batch Queries - Process up to 100 queries in a single request
  • 🛡️ Smart Retries - Built-in retry logic handles network issues automatically

Installation

Using pip

pip install serpshot

Using uv

uv add serpshot

Get Your API Key

Free to use, just register to get your API key.

Quick Start

from serpshot import SerpShot

with SerpShot(api_key="your-api-key") as client:
    response = client.search("Python programming")
    for result in response.results:
        print(f"{result.title}: {result.link}")

Set SERPSHOT_API_KEY env var to skip passing the key explicitly:

with SerpShot() as client:
    response = client.search("Python programming")

Async:

import asyncio
from serpshot import AsyncSerpShot

async def main():
    async with AsyncSerpShot() as client:
        response = await client.search("Python programming")

asyncio.run(main())

MCP Integration

SerpShot includes a built-in MCP server, letting AI assistants (Claude, Cursor, Windsurf, etc.) call Google Search directly as a tool.

Install MCP extra

pip install 'serpshot[mcp]'
# or
uv add 'serpshot[mcp]'

Configuration

Add the following to your MCP client's config (Claude Code, Cursor, Windsurf, etc.):

{
  "mcpServers": {
    "serpshot": {
      "command": "python",
      "args": ["-m", "serpshot.mcp"],
      "env": { "SERPSHOT_API_KEY": "your_key_here" }
    }
  }
}

Or with uvx (no install required):

{
  "mcpServers": {
    "serpshot": {
      "command": "uvx",
      "args": ["--from", "serpshot[mcp]", "serpshot-mcp"],
      "env": { "SERPSHOT_API_KEY": "your_key_here" }
    }
  }
}

Available MCP Tools

Tool Description
google_search Search Google — returns organic results, supports query, num, gl, hl
google_image_search Search Google Images — returns image results with thumbnails and source URLs

API Reference

SerpShot(api_key, base_url, timeout, max_retries)

Parameter Default Description
api_key env var SerpShot API key, falls back to SERPSHOT_API_KEY
base_url None Custom API endpoint
timeout 30.0 Request timeout in seconds
max_retries 3 Maximum retry attempts

Use AsyncSerpShot for async usage — same interface, all methods are awaitable.

search(query, ...)

Parameter Default Description
query required Search string or list of strings (max 100)
num 10 Results per page (1–100)
page 1 Page number
gl "us" Country code
hl "en" Interface language
lr Content language restriction
location Location for local search

Returns SearchResponse, or list[SearchResponse] when query is a list.

image_search(query, ...)

Same parameters as search() except lr and location are not supported.

get_available_credits()

with SerpShot() as client:
    print(client.get_available_credits())

Response Models

SearchResponse

Field Type Description
query str Original query
total_results str Estimated total (e.g. "About 12,300,000 results")
search_time str Execution time in seconds
results list list[SearchResult] or list[ImageResult]
credits_used int Credits consumed

SearchResult: title, link, snippet, position

ImageResult: title, link, thumbnail, source, source_link, width, height, position

Examples

Batch Search

with SerpShot() as client:
    responses = client.search(["Python", "JavaScript", "Rust"], num=10)
    for r in responses:
        print(f"{r.query}: {r.results[0].title}")

Error Handling

from serpshot import SerpShot, AuthenticationError, RateLimitError, InsufficientCreditsError, APIError, NetworkError

try:
    with SerpShot() as client:
        response = client.search("test query")
except AuthenticationError:
    print("Invalid API key")
except RateLimitError as e:
    print(f"Rate limited, retry after {e.retry_after}s")
except InsufficientCreditsError as e:
    print(f"Need {e.credits_required} credits")
except (APIError, NetworkError) as e:
    print(f"Error: {e}")

The SDK handles rate limiting automatically with exponential backoff. Track credit usage via response.credits_used.

Development

git clone https://github.com/downdawn/serpshot-python.git
cd serpshot-python
uv sync --dev
pytest

License

MIT — see LICENSE.

Support

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

serpshot-0.2.1.tar.gz (73.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

serpshot-0.2.1-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

File details

Details for the file serpshot-0.2.1.tar.gz.

File metadata

  • Download URL: serpshot-0.2.1.tar.gz
  • Upload date:
  • Size: 73.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.5

File hashes

Hashes for serpshot-0.2.1.tar.gz
Algorithm Hash digest
SHA256 703068a3f6961d46442da9f122875009e746ca89b66cfc12b9dd34f5ade48a63
MD5 b79422b603d17d16792dab146f409d65
BLAKE2b-256 625d0e65a9e18d5b9c34f9c193e4b5dc518feba512c7d4700e8deee7d30aab07

See more details on using hashes here.

File details

Details for the file serpshot-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: serpshot-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 19.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.5

File hashes

Hashes for serpshot-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 1685539b1968c91ee01bf3b1bacec6d8f5306b56329f2fd675a2ce2d57d5def2
MD5 67936250b898adb42f8c656df12b6b51
BLAKE2b-256 79f77ad379af8688c4dfec9cec77fb46ca53cebdd84088e544954463374f8c18

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page