DDGS (formerly duckduckgo-search)
DDGS is a Python metasearch library that aggregates results from various web search services, including DuckDuckGo, Bing, and Google, without requiring an API key. It provides programmatic access to different search types such as text, images, videos, news, and books. The library is actively maintained, with frequent releases; the current version is 9.13.0.
Warnings
- breaking The package name has been officially changed from `duckduckgo-search` to `ddgs`. Continuing to use the old package name will lead to `RuntimeWarning` and may prevent access to newer features and bug fixes.
- breaking Python 3.9 support was dropped in version 9.9.0. Projects using `ddgs` (version 9.9.0+) must use Python 3.10 or newer.
- gotcha The library acts as a metasearch tool, using various backends (DuckDuckGo, Bing, Google, etc.). Specific backends can be unstable or have their scraping methods change, leading to temporary issues or irrelevant results. This often necessitates updating the library.
- gotcha Frequent or high-volume requests without proper proxy management can lead to rate limiting or IP bans from search engines.
- gotcha The search methods (e.g., `text()`, `images()`) always return a list of dictionaries, even when `max_results=1`. Users might incorrectly assume a single dictionary is returned.
Install
-
pip install ddgs
Imports
- DDGS
from ddgs import DDGS
Quickstart
from ddgs import DDGS
# Initialize DDGS with optional proxy or timeout
ddgs_client = DDGS(timeout=20)
# Perform a text search
results = ddgs_client.text(
"python programming tutorials",
region="wt-wt", # worldwide
safesearch="moderate",
timelimit="y", # past year
max_results=5
)
for r in results:
print(f"Title: {r.get('title')}\nURL: {r.get('href')}\n")
# Example of an image search
image_results = ddgs_client.images(
"cute puppies",
region="us-en",
safesearch="off",
max_results=3
)
if image_results:
print(f"First image URL: {image_results[0].get('image')}")