Search for words, documents, images, news, maps and text translation using the DuckDuckGo.com search engine.
—
Complete command-line interface for all DuckDuckGo search operations with result saving, downloading, and output formatting options. The CLI provides access to all search functionality through terminal commands.
Main CLI interface functions providing command-line access to all search capabilities.
def cli() -> None:
"""Main CLI command group for duckduckgo_search operations."""
def safe_entry_point() -> None:
"""Safe CLI entry point with exception handling."""The CLI is automatically installed with the package and available through multiple entry points:
Via console script (recommended):
ddgs --helpVia Python module:
python -m duckduckgo_search --helpDisplay package version information.
ddgs versionPerform text-based web searches with comprehensive filtering options.
ddgs text [OPTIONS]Options:
-k, --keywords TEXT (required): Text search keywords/query-r, --region TEXT: Region code (us-en, ru-ru, etc.)-s, --safesearch [on|moderate|off]: Safe search level (default: moderate)-t, --timelimit [d|w|m|y]: Time filter (day, week, month, year)-m, --max_results INTEGER: Maximum number of results-o, --output TEXT: Output format (csv, json) or filename with extension-d, --download: Download search results-dd, --download-directory TEXT: Custom download directory-b, --backend [auto|html|lite]: Search backend (default: auto)-th, --threads INTEGER: Download threads (default: 10)-p, --proxy TEXT: Proxy URL (e.g., socks5://127.0.0.1:9150)-v, --verify: SSL verification (default: True)Search for images with extensive filtering options.
ddgs images [OPTIONS]Options:
-k, --keywords TEXT (required): Image search keywords/query-r, --region TEXT: Region code (default: us-en)-s, --safesearch [on|moderate|off]: Safe search level (default: moderate)-t, --timelimit [Day|Week|Month|Year]: Time filter-size, --size [Small|Medium|Large|Wallpaper]: Image size filter-c, --color [color|Monochrome|Red|Orange|Yellow|Green|Blue|Purple|Pink|Brown|Black|Gray|Teal|White]: Color filter-type, --type_image [photo|clipart|gif|transparent|line]: Image type filter-l, --layout [Square|Tall|Wide]: Layout filter-lic, --license_image [any|Public|Share|ShareCommercially|Modify|ModifyCommercially]: License filter-m, --max_results INTEGER: Maximum number of results-o, --output TEXT: Output format (csv, json) or filename with extension-d, --download: Download image results-dd, --download-directory TEXT: Custom download directory-th, --threads INTEGER: Download threads (default: 10)-p, --proxy TEXT: Proxy URL-v, --verify: SSL verification (default: True)Search for videos with filtering options.
ddgs videos [OPTIONS]Options:
-k, --keywords TEXT (required): Video search keywords/query-r, --region TEXT: Region code (default: us-en)-s, --safesearch [on|moderate|off]: Safe search level (default: moderate)-t, --timelimit [d|w|m]: Time filter (day, week, month)-res, --resolution [high|standart]: Video resolution filter-d, --duration [short|medium|long]: Duration filter-lic, --license_videos [creativeCommon|youtube]: License filter-m, --max_results INTEGER: Maximum number of results-o, --output TEXT: Output format (csv, json) or filename with extension-p, --proxy TEXT: Proxy URL-v, --verify: SSL verification (default: True)Search for news articles with time-based filtering.
ddgs news [OPTIONS]Options:
-k, --keywords TEXT (required): News search keywords/query-r, --region TEXT: Region code (default: us-en)-s, --safesearch [on|moderate|off]: Safe search level (default: moderate)-t, --timelimit [d|w|m|y]: Time filter (day, week, month, year)-m, --max_results INTEGER: Maximum number of results-o, --output TEXT: Output format (csv, json) or filename with extension-p, --proxy TEXT: Proxy URL-v, --verify: SSL verification (default: True)Text search:
# Basic text search
ddgs text -k "python programming"
# Text search with filters
ddgs text -k "machine learning" -r us-en -t w -m 10
# Text search with output to file
ddgs text -k "data science" -o results.json
# Text search with CSV output
ddgs text -k "web development" -o myresults.csvImage search:
# Basic image search
ddgs images -k "cats"
# Image search with filters
ddgs images -k "mountains" -size Large -c Green -type photo -m 20
# Image search with download
ddgs images -k "wallpapers" -size Wallpaper -d -m 5
# Image search with custom download directory
ddgs images -k "nature" -dd ./nature_images -d -m 10Video search:
# Basic video search
ddgs videos -k "cooking tutorial"
# Video search with filters
ddgs videos -k "programming" -res high -d medium -m 15
# Video search with Creative Commons filter
ddgs videos -k "educational content" -lic creativeCommon -m 10News search:
# Basic news search
ddgs news -k "technology"
# Recent news search
ddgs news -k "climate change" -t d -m 20
# Regional news search
ddgs news -k "politics" -r uk-en -t wChain multiple searches:
# Multiple searches in sequence
ddgs text -k "python" -o python_results.json && \
ddgs images -k "python logo" -o python_images.jsonUsing proxy:
# Search through Tor proxy
ddgs text -k "privacy tools" -p socks5://127.0.0.1:9150
# Search through HTTP proxy
ddgs text -k "research" -p http://proxy.example.com:8080Bulk downloading:
# Download text search results
ddgs text -k "tutorials" -d -th 20 -m 50
# Download images with custom directory
ddgs images -k "photography" -dd ./photos -d -th 15 -m 30JSON output format:
# Save as JSON
ddgs text -k "example" -o output.json
# JSON output contains structured data:
# [
# {
# "title": "Example Title",
# "href": "https://example.com",
# "body": "Example description..."
# }
# ]CSV output format:
# Save as CSV
ddgs text -k "example" -o output.csv
# CSV output contains columns: title,href,bodySet default proxy via environment variable:
export DDGS_PROXY="socks5://127.0.0.1:9150"
ddgs text -k "search query" # Uses DDGS_PROXY automaticallySupported proxy formats:
http://proxy.example.com:8080https://proxy.example.com:8080socks5://127.0.0.1:9150http://user:pass@proxy.example.com:8080tb (expands to socks5://127.0.0.1:9150)The CLI includes comprehensive error handling:
# Rate limiting errors are handled gracefully
ddgs text -k "query" -m 1000 # May trigger rate limiting
# Timeout errors with retry suggestions
ddgs text -k "query" -p socks5://slow-proxy:9150
# Invalid parameters are caught and explained
ddgs text -k "query" -t invalid_time # Shows valid optionsBy default, results are displayed interactively with pagination. Press Enter to view each result.
Results can be exported to JSON or CSV formats:
For text and image searches, results can be downloaded to local files:
Threading control for downloads:
# Use more threads for faster downloads (default: 10)
ddgs images -k "photos" -d -th 20
# Use fewer threads for slower connections
ddgs images -k "photos" -d -th 5Shell scripting integration:
#!/bin/bash
# Search and process results
ddgs news -k "breaking news" -o news.json
python -c "
import json
with open('news.json') as f:
news = json.load(f)
for article in news[:5]:
print(f'{article[\"title\"]} - {article[\"source\"]}')
"Automated data collection:
# Daily news collection script
#!/bin/bash
DATE=$(date +%Y%m%d)
ddgs news -k "technology news" -t d -o "tech_news_$DATE.json"
ddgs news -k "business news" -t d -o "business_news_$DATE.json"Install with Tessl CLI
npx tessl i tessl/pypi-duckduckgo-search