serpapi.Client is fully synchronous under the hood (uses requests), so calling it from async code, like inside a FastAPI route, blocks the event loop.
Checked and there's no async entry point right now:
import serpapi
[m for m in dir(serpapi.Client) if not m.startswith('_')]
['BASE_DOMAIN', 'DASHBOARD_URL', 'USER_AGENT', 'account', 'locations', 'request', 'search', 'search_archive']
A couple options that could fix this:
- Add an async def search_async(...) method that just wraps the existing search() using run_in_executor, small and low risk
- Add a proper AsyncClient built on httpx or aiohttp for true non-blocking requests, more work but avoids the thread pool overhead
Not sure which direction you'd rather take, happy to build either one and add tests once there's some agreement on approach.
serpapi.Client is fully synchronous under the hood (uses requests), so calling it from async code, like inside a FastAPI route, blocks the event loop.
Checked and there's no async entry point right now:
A couple options that could fix this:
Not sure which direction you'd rather take, happy to build either one and add tests once there's some agreement on approach.