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

未关闭
#27 5 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
38/100
Issue 类型
功能
描述清晰度
基本清楚
活跃度
冷清
技术栈
python
领域
api

调研方向

Start by locating the current HTTP layer that uses requests, then read the linked HTTPX compatibility guide and review how the existing synchronous Client API is exposed. Done means preserving current synchronous usage, adding asyncio-compatible calls without breaking users, and including benchmarks to compare performance.

由索引模型根据 Issue 内容生成。

描述

improvement

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: https://github.com/serpapi/google-search-results-python/issues/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.

主要语言
Python
星标
173
派生
24
平均合并
1 天 17 小时
30 天内合并 PR
2

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

serpapi/serpapi-python 的其他 Issue

查看 serpapi/serpapi-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。