DuckDuckGo
DuckDuckGo 是注重隱私的搜尋引擎
不追蹤使用者、不記錄搜尋歷史、不做個人化廣告
Google:根據你的歷史記錄個人化搜尋結果
DuckDuckGo:每次搜尋都像新使用者,結果不受個人化影響
DuckDuckGo 沒有提供官方完整搜尋結果 API(有 Instant Answer / Zero-click API,但不是完整 SERP)
參考:DuckDuckGo Privacy — DuckDuckGo Help Pages
ddgs Python Library
ddgs(Dux Distributed Global Search)是非官方 Python metasearch library,聚合多個搜尋來源(包括 DuckDuckGo)的結果
pip install -U ddgs # 基本安裝
pip install -U ddgs[api] # + FastAPI server
pip install -U ddgs[mcp] # + MCP server (stdio)
| 項目 | 說明 |
|---|---|
| 套件名稱 | ddgs(前身:duckduckgo-search,已改名) |
| 最新版本 | 9.14.1(2026-04-20) |
| 授權 | MIT |
| 作者 | deedy5 |
| API Key | ❌ 不需要 |
⚠️ 非官方,不隸屬 DuckDuckGo,使用前確認符合 DuckDuckGo ToS
參考:ddgs · PyPI
基本用法
from ddgs import DDGS
results = DDGS().text(
query="LLM agent tool use",
region="wt-wt", # wt-wt = worldwide(不限地區)
safesearch="moderate", # on | moderate | off
timelimit="w", # d=一天 / w=一週 / m=一月 / y=一年
max_results=5
)
for r in results:
print(r["title"], r["href"], r["body"])
回傳欄位:title、href(URL)、body(摘要)
支援的搜尋類型
| Method | 說明 |
|---|---|
.text() |
一般文字搜尋 |
.news() |
新聞搜尋,有 timelimit 可用 |
.images() |
圖片搜尋 |
.videos() |
影片搜尋 |
.books() |
書籍搜尋 |
.extract() |
抽取指定 URL 的網頁內容 |
在 Async 環境使用
ddgs 本身是同步 library,在 async context 裡用 asyncio.to_thread 包裝:
import asyncio
from ddgs import DDGS
async def search(query: str):
return await asyncio.to_thread(
lambda: DDGS().text(query, max_results=5)
)
results = asyncio.run(search("transformer architecture"))
LangChain 整合
from langchain_community.tools import DuckDuckGoSearchRun
from langchain_community.tools import DuckDuckGoSearchResults
# 回傳單一字串(簡潔)
tool = DuckDuckGoSearchRun()
tool.invoke("what is HNSW?")
# 回傳多筆結果 + metadata
tool = DuckDuckGoSearchResults(num_results=5)
tool.invoke("what is HNSW?")
底層使用 ddgs,不需要額外設定
參考:DuckDuckGo search integrations — LangChain Docs
使用限制
優點:
不需要 API Key,免費
隱私友好,搜尋不被記錄
MIT license
有內建 API Server(FastAPI)和 MCP Server
缺點:
非官方,無 SLA 保證
高頻查詢容易被 rate limit 或封鎖
結果品質不如 Tavily 針對 LLM 優化
沒有 AI 合成回答
body 是短摘要,不是完整頁面內容
跟 Tavily / SearXNG 的比較
| 比較 | ddgs | Tavily | SearXNG |
|---|---|---|---|
| 官方 API | ❌ 非官方 | ✅ 官方 | ✅ 自架 |
| API Key | 不需要 | 需要(tvly-...) |
不需要 |
| 費用 | 免費 | Free 1,000 credits/月 | 免費(自架成本) |
| AI 合成回答 | ❌ | ✅ | ❌ |
| Rate limit 風險 | 高 | 低 | 中(取決於上游) |
| LLM 優化 | 低 | 高 | 低 |
| 適合情境 | 快速 prototype | 正式 RAG / Agent | 隱私優先、自架 |