CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-duckduckgo-search

Search for words, documents, images, news, maps and text translation using the DuckDuckGo.com search engine.

Pending
Overview
Eval results
Files

text-search.mddocs/

Text Search

Performs comprehensive text-based web searches using DuckDuckGo's search engine with advanced filtering options, regional settings, multiple backend support, and automatic fallback mechanisms for reliable results.

Capabilities

Text Search Function

Searches the web for text content using specified keywords with comprehensive filtering and configuration options.

def text(
    keywords: str,
    region: str | None = None,
    safesearch: str = "moderate",
    timelimit: str | None = None,
    backend: str = "auto",  
    max_results: int | None = None
) -> list[dict[str, str]]:
    """
    DuckDuckGo text search. Query params: https://duckduckgo.com/params.

    Parameters:
    - keywords (str): Search keywords/query terms
    - region (str, optional): Region code (us-en, uk-en, ru-ru, etc.). Defaults to None.
    - safesearch (str): Safety filter level ("on", "moderate", "off"). Defaults to "moderate".
    - timelimit (str, optional): Time filter ("d", "w", "m", "y" for day, week, month, year). Defaults to None.
    - backend (str): Search backend ("auto", "html", "lite", "bing"). Defaults to "auto".
        - "auto": Try all backends in random order with fallback
        - "html": Use html.duckduckgo.com backend  
        - "lite": Use lite.duckduckgo.com backend
        - "bing": Use bing.com backend
    - max_results (int, optional): Maximum number of results to return. If None, returns results from first response only. Defaults to None.

    Returns:
    List of dictionaries with search results containing:
    - "title" (str): Result title
    - "href" (str): Result URL  
    - "body" (str): Result description/snippet

    Raises:
    - DuckDuckGoSearchException: Base exception for search errors
    - RatelimitException: API request rate limit exceeded
    - TimeoutException: Request timeout occurred
    """

Usage Examples

Basic text search:

from duckduckgo_search import DDGS

with DDGS() as ddgs:
    results = ddgs.text("python programming")
    for result in results:
        print(f"Title: {result['title']}")
        print(f"URL: {result['href']}")
        print(f"Summary: {result['body']}")
        print("---")

Text search with filters:

from duckduckgo_search import DDGS

with DDGS() as ddgs:
    # Search with region, time filter, and result limit
    results = ddgs.text(
        keywords="machine learning tutorials",
        region="us-en",
        safesearch="moderate", 
        timelimit="w",  # Past week
        max_results=10
    )
    
    for result in results:
        print(f"Title: {result['title']}")
        print(f"URL: {result['href']}")
        print("---")

Text search with specific backend:

from duckduckgo_search import DDGS

with DDGS() as ddgs:
    # Use specific backend (html in this case)
    results = ddgs.text(
        keywords="data science",
        backend="html",
        max_results=5
    )
    
    for result in results:
        print(f"Found: {result['title']}")
        print(f"Link: {result['href']}")

Text search with proxy and custom configuration:

from duckduckgo_search import DDGS

# Configure with proxy and custom settings
with DDGS(
    proxy="socks5://127.0.0.1:9150",  # Tor proxy
    timeout=30,
    verify=True
) as ddgs:
    results = ddgs.text(
        keywords="secure communications",
        safesearch="on",
        max_results=20
    )
    
    print(f"Found {len(results)} results")
    for result in results:
        print(f"- {result['title']}: {result['href']}")

Error Handling

Handle common search errors:

from duckduckgo_search import DDGS
from duckduckgo_search.exceptions import (
    DuckDuckGoSearchException,
    RatelimitException, 
    TimeoutException
)

try:
    with DDGS() as ddgs:
        results = ddgs.text("test query", max_results=50)
        print(f"Retrieved {len(results)} results")
        
except RatelimitException as e:
    print(f"Rate limit exceeded: {e}")
    # Implement retry logic with backoff
    
except TimeoutException as e:
    print(f"Request timed out: {e}")
    # Retry with different backend or increased timeout
    
except DuckDuckGoSearchException as e:
    print(f"Search error: {e}")
    # Handle other search-related errors

Parameter Details

Region Codes

Common region codes for localized search results:

  • "us-en": United States (English)
  • "uk-en": United Kingdom (English)
  • "au-en": Australia (English)
  • "ca-en": Canada (English)
  • "de-de": Germany (German)
  • "fr-fr": France (French)
  • "ru-ru": Russia (Russian)
  • "jp-jp": Japan (Japanese)
  • "cn-zh": China (Chinese)

SafeSearch Options

  • "on": Strict filtering, blocks adult content
  • "moderate": Moderate filtering (default)
  • "off": No filtering

Time Limits

  • "d": Past day
  • "w": Past week
  • "m": Past month
  • "y": Past year

Backend Options

  • "auto": Automatic backend selection with fallback (recommended)
  • "html": HTML backend (html.duckduckgo.com)
  • "lite": Lite backend (lite.duckduckgo.com)
  • "bing": Bing backend (currently primary backend)

Note: Backend availability may change. The "auto" option provides the most reliable experience with automatic fallback.

Install with Tessl CLI

npx tessl i tessl/pypi-duckduckgo-search

docs

cli.md

image-search.md

index.md

news-search.md

text-search.md

video-search.md

tile.json