DuckDuckGo Search
Privacy-focused web search using DuckDuckGo
Overview
DuckDuckGo is a privacy-focused search engine. This tool provides web search, news, and image search capabilities without requiring an API key.
The user asks a question; the agent searches DuckDuckGo and returns relevant results.
Installation
pip install "praisonai[tools]"No API key required!
Quick Start
- Simple Usage
python from praisonai_tools import DuckDuckGoTool # Initialize ddg = DuckDuckGoTool() # Search results = ddg.search("Python programming") print(results) - With Configuration
Use the same tool with an agent — see Usage with Agent below, or pass env vars and options from the sections above.
Usage with Agent
from praisonaiagents import Agent
from praisonai_tools import DuckDuckGoTool
agent = Agent(
name="Researcher",
instructions="You are a research assistant. Use DuckDuckGo to search for information.",
tools=[DuckDuckGoTool()]
)
response = agent.chat("Search for the latest Python tutorials")
print(response)Available Methods
search(query, max_results=5)
Search the web.
from praisonai_tools import DuckDuckGoTool
ddg = DuckDuckGoTool()
results = ddg.search("machine learning basics", max_results=3)
# Returns:
# [
# {"title": "...", "url": "...", "snippet": "..."},
# ...
# ]news(query, max_results=5)
Get news articles.
news = ddg.news("AI technology", max_results=5)
# Returns:
# [
# {"title": "...", "url": "...", "source": "...", "date": "...", "snippet": "..."},
# ...
# ]images(query, max_results=5)
Search for images.
images = ddg.images("cute cats", max_results=3)
# Returns:
# [
# {"title": "...", "image_url": "...", "thumbnail": "...", "source": "..."},
# ...
# ]Configuration Options
ddg = DuckDuckGoTool(
proxy="socks5://localhost:9050", # Optional: use proxy
timeout=10 # Request timeout in seconds
)Function-Based Usage
from praisonai_tools import duckduckgo_search
# Quick search without instantiating class
results = duckduckgo_search("latest tech news", max_results=5)CLI Usage
# Use with praisonai (no API key needed)
praisonai --tools DuckDuckGoTool "Search for Python best practices"Error Handling
from praisonai_tools import DuckDuckGoTool
ddg = DuckDuckGoTool()
results = ddg.search("my query")
if results and "error" in results[0]:
print(f"Error: {results[0]['error']}")
else:
for r in results:
print(f"- {r['title']}: {r['url']}")Common Errors
| Error | Cause | Solution |
|---|---|---|
duckduckgo-search not installed | Missing dependency | Run pip install duckduckgo-search |
RatelimitException | Too many requests | Add delay between requests or use proxy |
TimeoutException | Request timeout | Increase timeout or check network |
Advantages
- No API key required – Works out of the box
- Privacy-focused – No tracking
- Multiple search types – Web, news, images
- Free – No usage limits (respect rate limits)
How It Works
Best Practices
No API key needed
DuckDuckGo works without credentials — ideal for quick prototypes and privacy-sensitive use.
Cap result count
Request a small number of results so the agent processes fewer tokens and answers faster.
Fall back on failure
Wrap the search in error handling so the agent can switch to another search tool if a request fails.