Skip to content

[Proposal] Support Python asyncio by migrating to httpx from requests #27

@adarshdigievo

Description

@adarshdigievo

Motivation

  • We currently use the requests library for sending HTTP requests. While requests is stable and widely used, it is synchronous-only and does not support Python’s asyncio concurrency model.
  • This limits users who build async Python applications. Even if their application code uses async / await, the HTTP layer still blocks unless the underlying client library also supports async. A related request came up in our deprecated library: [Async] Provide async requests for GoogleSearch google-search-results-python#72
  • Supporting async is increasingly expected in modern Python SDKs, especially for APIs, since the async pattern works well with I/O blocked apps.
  • Most of the popular Python packages are already using httpx: eg, OpenAI and Anthropic Python SDKs, and Python MCP SDK

Plan:

  • Migrate the HTTP layer from requests to httpx.
  • Ref: Official migration guide from httpx: https://www.python-httpx.org/compatibility/.
  • The migration should require minimal changes because HTTPX is mostly compatible with the requests API style.
  • The changes will be made with full backward compatibility; there will not be any breakages for current users.
  • I will also add benchmarks to assess if there are any changes to performance as a part of this migration.
  • We will support the existing pattern:
import os
import serpapi

def send():
  client = serpapi.Client(api_key=os.getenv("SERPAPI_KEY"))
  results = client.search({
    "engine": "google",
    "q": "coffee"
  })

  print(results)

and will also add support for async calls:

import os
import serpapi

async def send():
  client = serpapi.Client(api_key=os.getenv("SERPAPI_KEY"))
  results = await client.search({
    "engine": "google",
    "q": "coffee"
  })

  print(results)

Users can choose the pattern that best fits their application.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions