| name | serpapi-local-dev-loop |
| description | Configure SerpApi local development with cached responses and test fixtures.
Use when building search integrations, avoiding API calls during development,
or setting up reproducible test data from SerpApi.
Trigger: "serpapi dev setup", "serpapi local", "test serpapi locally".
|
| allowed-tools | Read, Write, Edit, Bash(npm:*), Bash(npx:*), Grep |
| version | 1.4.0 |
| license | MIT |
| author | Jeremy Longshore <jeremy@intentsolutions.io> |
| tags | ["saas","search","seo","serpapi"] |
| compatibility | Designed for Claude Code |
SerpApi Local Dev Loop
Overview
Set up local development for SerpApi with response caching, fixture recording, and offline testing. SerpApi charges per search, so caching results locally is critical for cost-effective development.
Instructions
Step 1: Record Real Responses as Fixtures
import serpapi, json, os, hashlib
def record_fixture(params: dict, fixtures_dir="tests/fixtures"):
"""Run a real search and save the response as a fixture file."""
os.makedirs(fixtures_dir, exist_ok=True)
client = serpapi.Client(api_key=os.environ["SERPAPI_API_KEY"])
result = client.search(**params)
key = hashlib.md5(json.dumps(params, sort_keys=True).encode()).hexdigest()[:12]
path = os.path.join(fixtures_dir, f"{params['engine']}_{key}.json")
with open(path, "w") as f:
json.dump(dict(result), f, indent=2)
print(f"Recorded: {path}")
record_fixture({"engine": "google", "q": "python tutorial", "num": 5})
record_fixture({"engine": "youtube", "search_query": "react hooks"})
record_fixture({"engine": "bing", "q": "machine learning"})
Step 2: Mock Client for Testing