Skip to main content

Crate duckduckgo_search_cli

Crate duckduckgo_search_cli 

Source
Expand description

§duckduckgo-search-cli

Rust CLI for searching DuckDuckGo via pure HTTP, with structured JSON output for LLM consumption. No paid API. No Chrome (during the search phase). No cache. Universal cross-platform (Linux including Alpine/NixOS/Flatpak/Snap, macOS including Apple Silicon, Windows including cmd.exe and PowerShell).

§Module Structure

ModuleResponsibility
cliClap structs (command-line argument parsing).
httpreqwest::Client construction and User-Agent selection.
searchURL building and HTTP request to the DuckDuckGo endpoint.
extractionHTML parsing with scraper and ad filtering.
pipelineSingle/multi orchestration, deduplication and source reading.
parallelMulti-query fan-out with JoinSet, Semaphore, CancellationToken.
outputJSON serialization and stdout writing (ONLY module with println!).
platformCross-platform initialization (UTF-8 on Windows, TTY detect).
typesShared structs and enums.
errorError codes and exit codes.
contentHTTP + readability extraction for --fetch-content (iter. 5).
content_fetchParallel fan-out + per-host rate-limit (iter. 5 / 6).
selectorsLoading of external SelectorConfig (iter. 6).
signalsCross-platform signal handlers (SIGPIPE, Ctrl+C).
config_initinit-config subcommand (iter. 6).
pathsPath validation and sanitization for I/O.
browserHeadless Chrome cross-platform under feature chrome (iter.7).

§Entry Point

The public function run is called by main.rs and returns an exit code as specified in section 17.7 of the specification.

Modules§

aggregation
Result aggregation across sub-queries for the deep-research pipeline.
browser
Cross-platform detection and launch of headless Chrome via chromiumoxide.
cli
CLI argument definitions via clap derive.
config_init
Implements the init-config subcommand — copies TOMLs embedded in the binary to the user’s configuration directory, allowing local editing without recompiling.
content
Full text content extraction from URLs (flag --fetch-content).
content_fetch
Parallel fan-out for content extraction (flag --fetch-content).
decomposition
Query decomposition for deep-research fan-out.
deep_research
Deep research subcommand — query fan-out, aggregation, and synthesis.
error
Structured error codes as defined in specification section 14.3.
extraction
Extraction of search results from DuckDuckGo HTML.
http
reqwest::Client construction and User-Agent selection.
identity
Browser identity pool for adaptive anti-bot rotation (WS-26).
output
Formatting and emission of the final result to stdout or a file.
parallel
Multi-query parallelism with JoinSet, Semaphore, staggered launch and CancellationToken.
paths
Path validation and sanitization for I/O operations.
pipeline
Orchestration of the CLI execution flow.
platform
Platform detection and cross-platform initialization.
search
URL construction and search request execution for DuckDuckGo.
selectors
Lazy loading of SelectorConfig with precedence:
signals
Cross-platform signal handlers for the CLI binary.
synthesis
Heuristic synthesis of an aggregated result list into a single report.
types
Shared data types used across the application.

Functions§

run
Library entry point. Called by main.rs.