[Proposal] Support Python `asyncio` by migrating to `httpx` from `requests`
还没有人认领这个 Issue。
评估
调研方向
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 内容生成。
描述
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
asyncpattern 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
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
serpapi/serpapi-python 的其他 Issue
-
improvement
难度 3/5 1-2 天 新手友好度 35/100
serpapi/serpapi-python#17 · 2 条评论 · 1 个 reaction ·
查看 serpapi/serpapi-python 的全部 Issue
相似的 Issue
-
link-check link-check:sphinx-theme
难度 2/5 1-3 小时 新手友好度 72/100
-
难度 2/5 1-3 小时 新手友好度 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
难度 2/5 1-3 小时 新手友好度 88/100
OpenHands/extensions#626 · 1 条评论 ·
-
难度 1/5 1 小时以内 新手友好度 90/100
CSCfi/sd-search-api#39 ·
-
难度 1/5 1 小时以内 新手友好度 90/100