DuckDuckGo Search

Programmatically search for text, news, images and videos using DuckDuckGo's search engine.

OG Image

github.com

phukon/duckduckgo_search

Features

  • πŸ” Text search functionality with rich results
  • 🌍 Region-specific searches
  • πŸ›‘οΈ SafeSearch options
  • ⏰ Time-limited searches
  • πŸ”„ Multiple backend support (HTML and Lite)
  • 🌐 Proxy support
  • πŸ“ Comprehensive logging
  • πŸ”’ Optional SSL verification
  • 🎭 Random User-Agent rotation

API Reference

DDGS Class Options

OptionTypeDefaultDescription
headersObject{}Custom HTTP headers
proxystringnullProxy server URL
timeoutnumber10000Request timeout in milliseconds
verifybooleantrueEnable/disable SSL verification

Search Options

OptionTypeDefaultDescription
keywordsstringRequiredSearch query
regionstring'wt-wt'Region code
safesearchstring'moderate'SafeSearch level
timelimitstringnullTime restriction
backendstring'auto'Search backend
maxResultsnumbernullMaximum results to return

Usage

import { DDGS } from "duckduckgo-search-api";
const ddgs = new DDGS();
async function search() {
  const results = await ddgs.text({
    keywords: "TypeScript tutorial",
    maxResults: 10,
  });
  console.log(results);
}

Advanced Options

const ddgs = new DDGS({
  headers: {
    // Custom headers
  },
  proxy: "http://proxy.example.com:8080",
  timeout: 15000,
  verify: false, // Disable SSL verification
});
const results = await ddgs.text({
  keywords: "TypeScript tutorial",
  region: "us-en",
  safesearch: "strict",
  timelimit: "y", // Past year
  backend: "html",
  maxResults: 25,
});

Error Handling

  • DuckDuckGoSearchError: General search errors
  • RatelimitError: Rate limiting issues / CAPTCHA
  • TimeoutError: Request timeouts

Roadmap

  • [x] Implement keyword search with HTML backend
  • [x] Random User-Agent rotation with browser impersonation
  • [x] Proxy support
  • [x] Custom timeout handling
  • [x] Region-specific searches
  • [x] Comprehensive logging system
  • [x] Error handling with custom errors
  • [x] SSL verification toggle
  • [ ] HTTP client that can impersonate web browsers
  • [x] Lite backend implementation
  • [ ] News search functionality
  • [ ] Image search functionality
  • [ ] Video search functionality
  • [ ] Cookie management
  • [ ] Comprehensive test suite
    • [ ] Unit tests
    • [ ] Integration tests
    • [ ] E2E tests
  • [ ] CI/CD Pipeline

Acknowledgments

Duckduckgo_search takes inspiration from the following projects:

πŸ“’ Disclaimer

This library is not affiliated with DuckDuckGo and is for educational purposes only. It is not intended for commercial use or any purpose that violates DuckDuckGo's Terms of Service. By using this library, you acknowledge that you will not use it in a way that infringes on DuckDuckGo's terms. The official DuckDuckGo website can be found at https://duckduckgo.com.

Tags

duckduckgo
search
browser

Contact

Need more project details, or interested in working together? Reach out to me directly at hello@rikiphukon.com. I'd be happy to connect!

← All Projects