Name | duckduckgo-search JSON |
Version |
5.2.1
JSON |
| download |
home_page | None |
Summary | Search for words, documents, images, news, maps and text translation using the DuckDuckGo.com search engine. |
upload_time | 2024-03-28 20:29:10 |
maintainer | None |
docs_url | None |
author | deedy5 |
requires_python | >=3.8 |
license | MIT License |
keywords |
python
duckduckgo
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
![Python >= 3.8](https://img.shields.io/badge/python->=3.8-red.svg) [![](https://badgen.net/github/release/deedy5/duckduckgo_search)](https://github.com/deedy5/duckduckgo_search/releases) [![](https://badge.fury.io/py/duckduckgo-search.svg)](https://pypi.org/project/duckduckgo-search) [![Downloads](https://static.pepy.tech/badge/duckduckgo-search)](https://pepy.tech/project/duckduckgo-search) [![Downloads](https://static.pepy.tech/badge/duckduckgo-search/week)](https://pepy.tech/project/duckduckgo-search)
# Duckduckgo_search<a name="TOP"></a>
Search for words, documents, images, videos, news, maps and text translation using the DuckDuckGo.com search engine. Downloading files and images to a local hard drive.
⚠️ Warning: it is better to use AsyncDDGS in asynchronous code</br>
:bangbang: v5.0 brings breaking changes: all functions are now not generators, but return a list of dictionaries.
## Table of Contents
* [Install](#install)
* [CLI version](#cli-version)
* [Duckduckgo search operators](#duckduckgo-search-operators)
* [Regions](#regions)
* [DDGS and AsyncDDGS classes](#ddgs-and-asyncddgs-classes)
* [Proxies](#proxies)
* [Exceptions](#exceptions)
* [1. text() - text search](#1-text---text-search-by-duckduckgocom)
* [2. answers() - instant answers](#2-answers---instant-answers-by-duckduckgocom)
* [3. images() - image search](#3-images---image-search-by-duckduckgocom)
* [4. videos() - video search](#4-videos---video-search-by-duckduckgocom)
* [5. news() - news search](#5-news---news-search-by-duckduckgocom)
* [6. maps() - map search](#6-maps---map-search-by-duckduckgocom)
* [7. translate() - translation](#7-translate---translation-by-duckduckgocom)
* [8. suggestions() - suggestions](#8-suggestions---suggestions-by-duckduckgocom)
## Install
```python
pip install -U duckduckgo_search
```
**[Optional]** To use the `text` function with `backend='html'` or `backend='lite'`:
```python
pip install -U duckduckgo_search[lxml]
```
## CLI version
```python3
ddgs --help
```
or
```python3
python -m duckduckgo_search --help
```
CLI examples:
```python3
# text search
ddgs text -k "axon regeneration"
# find and download pdf files via proxy (example: Tor browser)
ddgs text -k "neuroscience filetype:pdf" -r wt-wt -m 50 -d -p socks5://localhost:9150
# find and download images
ddgs images -k "gaz 14 chaika" -r ru-ru -type photo -m 500 -d
# get latest news and save to csv
ddgs news -k "hubble telescope" -m 50 -o csv
```
[Go To TOP](#TOP)
## Duckduckgo search operators
| Keywords example | Result|
| --- | --- |
| cats dogs | Results about cats or dogs |
| "cats and dogs" | Results for exact term "cats and dogs". If no results are found, related results are shown. |
| cats -dogs | Fewer dogs in results |
| cats +dogs | More dogs in results |
| cats filetype:pdf | PDFs about cats. Supported file types: pdf, doc(x), xls(x), ppt(x), html |
| dogs site:example.com | Pages about dogs from example.com |
| cats -site:example.com | Pages about cats, excluding example.com |
| intitle:dogs | Page title includes the word "dogs" |
| inurl:cats | Page url includes the word "cats" |
[Go To TOP](#TOP)
## Regions
<details>
<summary>expand</summary>
xa-ar for Arabia
xa-en for Arabia (en)
ar-es for Argentina
au-en for Australia
at-de for Austria
be-fr for Belgium (fr)
be-nl for Belgium (nl)
br-pt for Brazil
bg-bg for Bulgaria
ca-en for Canada
ca-fr for Canada (fr)
ct-ca for Catalan
cl-es for Chile
cn-zh for China
co-es for Colombia
hr-hr for Croatia
cz-cs for Czech Republic
dk-da for Denmark
ee-et for Estonia
fi-fi for Finland
fr-fr for France
de-de for Germany
gr-el for Greece
hk-tzh for Hong Kong
hu-hu for Hungary
in-en for India
id-id for Indonesia
id-en for Indonesia (en)
ie-en for Ireland
il-he for Israel
it-it for Italy
jp-jp for Japan
kr-kr for Korea
lv-lv for Latvia
lt-lt for Lithuania
xl-es for Latin America
my-ms for Malaysia
my-en for Malaysia (en)
mx-es for Mexico
nl-nl for Netherlands
nz-en for New Zealand
no-no for Norway
pe-es for Peru
ph-en for Philippines
ph-tl for Philippines (tl)
pl-pl for Poland
pt-pt for Portugal
ro-ro for Romania
ru-ru for Russia
sg-en for Singapore
sk-sk for Slovak Republic
sl-sl for Slovenia
za-en for South Africa
es-es for Spain
se-sv for Sweden
ch-de for Switzerland (de)
ch-fr for Switzerland (fr)
ch-it for Switzerland (it)
tw-tzh for Taiwan
th-th for Thailand
tr-tr for Turkey
ua-uk for Ukraine
uk-en for United Kingdom
us-en for United States
ue-es for United States (es)
ve-es for Venezuela
vn-vi for Vietnam
wt-wt for No region
___
</details>
[Go To TOP](#TOP)
## DDGS and AsyncDDGS classes
The DDGS and AsyncDDGS classes are used to retrieve search results from DuckDuckGo.com.
To use the AsyncDDGS class, you can perform asynchronous operations using Python's asyncio library.
To initialize an instance of the DDGS or AsyncDDGS classes, you can provide the following optional arguments:
```python3
class DDGS:
"""DuckDuckgo_search class to get search results from duckduckgo.com
Args:
headers (dict, optional): Dictionary of headers for the HTTP client. Defaults to None.
proxies (Union[dict, str], optional): Proxies for the HTTP client (can be dict or str). Defaults to None.
timeout (int, optional): Timeout value for the HTTP client. Defaults to 10.
"""
```
Here is an example of initializing the DDGS class.
```python3
from duckduckgo_search import DDGS
results = DDGS().text("python programming", max_results=5)
print(results)
```
Here is an example of initializing the AsyncDDGS class:
```python3
import asyncio
import logging
from duckduckgo_search import AsyncDDGS
async def aget_results(word):
results = await AsyncDDGS(proxies=None).text(word, max_results=100)
return results
async def main():
words = ["sun", "earth", "moon"]
tasks = [aget_results(w) for w in words]
results = await asyncio.gather(*tasks)
print(results)
if __name__ == "__main__":
logging.basicConfig(level=logging.DEBUG)
asyncio.run(main())
```
[Go To TOP](#TOP)
## Proxies
Proxy can be specified as a dictionary or just a string
```python
proxies = {"http": "socks5://localhost:9150", "https": "socks5://localhost:9150"}
proxies = "socks5://localhost:9150"
```
Use a proxy that changes ip on each request. Otherwise, use a new proxy with each DDGS or AsyncDDGS initialization.
*1. The easiest way. Launch the Tor Browser*
```python3
ddgs = DDGS(proxies="socks5://localhost:9150", timeout=20)
results = ddgs.text("something you need", max_results=50)
```
*2. Use any proxy server* (*example with [iproyal rotating residential proxies](https://iproyal.com?r=residential_proxies)*)
```python3
ddgs = DDGS(proxies="socks5://user:password@geo.iproyal.com:32325", timeout=20)
results = ddgs.text("something you need", max_results=50)
```
[Go To TOP](#TOP)
## Exceptions
Exceptions:
- `DuckDuckGoSearchException`: Base exception for duckduckgo_search errors.
- `RatelimitException`: Inherits from DuckDuckGoSearchException, raised for exceeding API request rate limits.
- `TimeoutException`: Inherits from DuckDuckGoSearchException, raised for API request timeouts.
[Go To TOP](#TOP)
## 1. text() - text search by duckduckgo.com
```python
def text(
keywords: str,
region: str = "wt-wt",
safesearch: str = "moderate",
timelimit: Optional[str] = None,
backend: str = "api",
max_results: Optional[int] = None,
) -> List[Dict[str, str]]:
"""DuckDuckGo text search generator. Query params: https://duckduckgo.com/params.
Args:
keywords: keywords for query.
region: wt-wt, us-en, uk-en, ru-ru, etc. Defaults to "wt-wt".
safesearch: on, moderate, off. Defaults to "moderate".
timelimit: d, w, m, y. Defaults to None.
backend: api, html, lite. Defaults to api.
api - collect data from https://duckduckgo.com,
html - collect data from https://html.duckduckgo.com,
lite - collect data from https://lite.duckduckgo.com.
max_results: max number of results. If None, returns results only from the first response. Defaults to None.
Returns:
List of dictionaries with search results.
Raises:
DuckDuckGoSearchException: Base exception for duckduckgo_search errors.
RatelimitException: Inherits from DuckDuckGoSearchException, raised for exceeding API request rate limits.
TimeoutException: Inherits from DuckDuckGoSearchException, raised for API request timeouts.
"""
```
***Example***
```python
results = DDGS().text('live free or die', region='wt-wt', safesearch='off', timelimit='y', max_results=10)
# Searching for pdf files
results = DDGS().text('russia filetype:pdf', region='wt-wt', safesearch='off', timelimit='y', max_results=10)
# async
results = await AsyncDDGS().text('sun', region='wt-wt', safesearch='off', timelimit='y', max_results=10)
```
[Go To TOP](#TOP)
## 2. answers() - instant answers by duckduckgo.com
```python
def answers(keywords: str) -> List[Dict[str, str]]:
"""DuckDuckGo instant answers. Query params: https://duckduckgo.com/params.
Args:
keywords: keywords for query,
Returns:
List of dictionaries with instant answers results.
Raises:
DuckDuckGoSearchException: Base exception for duckduckgo_search errors.
RatelimitException: Inherits from DuckDuckGoSearchException, raised for exceeding API request rate limits.
TimeoutException: Inherits from DuckDuckGoSearchException, raised for API request timeouts.
"""
```
***Example***
```python
results = DDGS().answers("sun")
# async
results = await AsyncDDGS().answers("sun")
```
[Go To TOP](#TOP)
## 3. images() - image search by duckduckgo.com
```python
def images(
keywords: str,
region: str = "wt-wt",
safesearch: str = "moderate",
timelimit: Optional[str] = None,
size: Optional[str] = None,
color: Optional[str] = None,
type_image: Optional[str] = None,
layout: Optional[str] = None,
license_image: Optional[str] = None,
max_results: Optional[int] = None,
) -> List[Dict[str, str]]:
"""DuckDuckGo images search. Query params: https://duckduckgo.com/params.
Args:
keywords: keywords for query.
region: wt-wt, us-en, uk-en, ru-ru, etc. Defaults to "wt-wt".
safesearch: on, moderate, off. Defaults to "moderate".
timelimit: Day, Week, Month, Year. Defaults to None.
size: Small, Medium, Large, Wallpaper. Defaults to None.
color: color, Monochrome, Red, Orange, Yellow, Green, Blue,
Purple, Pink, Brown, Black, Gray, Teal, White. Defaults to None.
type_image: photo, clipart, gif, transparent, line.
Defaults to None.
layout: Square, Tall, Wide. Defaults to None.
license_image: any (All Creative Commons), Public (PublicDomain),
Share (Free to Share and Use), ShareCommercially (Free to Share and Use Commercially),
Modify (Free to Modify, Share, and Use), ModifyCommercially (Free to Modify, Share, and
Use Commercially). Defaults to None.
max_results: max number of results. If None, returns results only from the first response. Defaults to None.
Returns:
List of dictionaries with images search results.
Raises:
DuckDuckGoSearchException: Base exception for duckduckgo_search errors.
RatelimitException: Inherits from DuckDuckGoSearchException, raised for exceeding API request rate limits.
TimeoutException: Inherits from DuckDuckGoSearchException, raised for API request timeouts.
"""
```
***Example***
```python
results = DDGS().images(
keywords="butterfly",
region="wt-wt",
safesearch="off",
size=None,
color="Monochrome",
type_image=None,
layout=None,
license_image=None,
max_results=100,
)
# async
results = await AsyncDDGS().images('sun', region='wt-wt', safesearch='off', max_results=20)
```
[Go To TOP](#TOP)
## 4. videos() - video search by duckduckgo.com
```python
def videos(
keywords: str,
region: str = "wt-wt",
safesearch: str = "moderate",
timelimit: Optional[str] = None,
resolution: Optional[str] = None,
duration: Optional[str] = None,
license_videos: Optional[str] = None,
max_results: Optional[int] = None,
) -> List[Dict[str, str]]:
"""DuckDuckGo videos search. Query params: https://duckduckgo.com/params.
Args:
keywords: keywords for query.
region: wt-wt, us-en, uk-en, ru-ru, etc. Defaults to "wt-wt".
safesearch: on, moderate, off. Defaults to "moderate".
timelimit: d, w, m. Defaults to None.
resolution: high, standart. Defaults to None.
duration: short, medium, long. Defaults to None.
license_videos: creativeCommon, youtube. Defaults to None.
max_results: max number of results. If None, returns results only from the first response. Defaults to None.
Returns:
List of dictionaries with videos search results.
Raises:
DuckDuckGoSearchException: Base exception for duckduckgo_search errors.
RatelimitException: Inherits from DuckDuckGoSearchException, raised for exceeding API request rate limits.
TimeoutException: Inherits from DuckDuckGoSearchException, raised for API request timeouts.
"""
```
***Example***
```python
results = DDGS().videos(
keywords="cars",
region="wt-wt",
safesearch="off",
timelimit="w",
resolution="high",
duration="medium",
max_results=100,
)
# async
results = await AsyncDDGS().videos('sun', region='wt-wt', safesearch='off', timelimit='y', max_results=10)
```
[Go To TOP](#TOP)
## 5. news() - news search by duckduckgo.com
```python
def news(
keywords: str,
region: str = "wt-wt",
safesearch: str = "moderate",
timelimit: Optional[str] = None,
max_results: Optional[int] = None,
) -> List[Dict[str, str]]:
"""DuckDuckGo news search. Query params: https://duckduckgo.com/params.
Args:
keywords: keywords for query.
region: wt-wt, us-en, uk-en, ru-ru, etc. Defaults to "wt-wt".
safesearch: on, moderate, off. Defaults to "moderate".
timelimit: d, w, m. Defaults to None.
max_results: max number of results. If None, returns results only from the first response. Defaults to None.
Returns:
List of dictionaries with news search results.
Raises:
DuckDuckGoSearchException: Base exception for duckduckgo_search errors.
RatelimitException: Inherits from DuckDuckGoSearchException, raised for exceeding API request rate limits.
TimeoutException: Inherits from DuckDuckGoSearchException, raised for API request timeouts.
"""
```
***Example***
```python
results = DDGS().news(keywords="sun", region="wt-wt", safesearch="off", timelimit="m", max_results=20)
# async
results = await AsyncDDGS().news('sun', region='wt-wt', safesearch='off', timelimit='d', max_results=10)
```
[Go To TOP](#TOP)
## 6. maps() - map search by duckduckgo.com
```python
def maps(
keywords,
place: Optional[str] = None,
street: Optional[str] = None,
city: Optional[str] = None,
county: Optional[str] = None,
state: Optional[str] = None,
country: Optional[str] = None,
postalcode: Optional[str] = None,
latitude: Optional[str] = None,
longitude: Optional[str] = None,
radius: int = 0,
max_results: Optional[int] = None,
) -> List[Dict[str, str]]:
"""DuckDuckGo maps search. Query params: https://duckduckgo.com/params.
Args:
keywords: keywords for query
place: if set, the other parameters are not used. Defaults to None.
street: house number/street. Defaults to None.
city: city of search. Defaults to None.
county: county of search. Defaults to None.
state: state of search. Defaults to None.
country: country of search. Defaults to None.
postalcode: postalcode of search. Defaults to None.
latitude: geographic coordinate (north-south position). Defaults to None.
longitude: geographic coordinate (east-west position); if latitude and
longitude are set, the other parameters are not used. Defaults to None.
radius: expand the search square by the distance in kilometers. Defaults to 0.
max_results: max number of results. If None, returns results only from the first response. Defaults to None.
Returns:
List of dictionaries with maps search results.
Raises:
DuckDuckGoSearchException: Base exception for duckduckgo_search errors.
RatelimitException: Inherits from DuckDuckGoSearchException, raised for exceeding API request rate limits.
TimeoutException: Inherits from DuckDuckGoSearchException, raised for API request timeouts.
"""
```
***Example***
```python
results = DDGS().maps("school", place="Uganda", max_results=50)
# async
results = await AsyncDDGS().maps('shop', place="Baltimor", max_results=10)
```
[Go To TOP](#TOP)
## 7. translate() - translation by duckduckgo.com
```python
def translate(
self,
keywords: str,
from_: Optional[str] = None,
to: str = "en",
) -> List[Dict[str, str]]:
"""DuckDuckGo translate.
Args:
keywords: string or list of strings to translate.
from_: translate from (defaults automatically). Defaults to None.
to: what language to translate. Defaults to "en".
Returns:
List od dictionaries with translated keywords.
Raises:
DuckDuckGoSearchException: Base exception for duckduckgo_search errors.
RatelimitException: Inherits from DuckDuckGoSearchException, raised for exceeding API request rate limits.
TimeoutException: Inherits from DuckDuckGoSearchException, raised for API request timeouts.
"""
```
***Example***
```python
keywords = 'school'
# also valid
keywords = ['school', 'cat']
results = DDGS().translate(keywords, to="de")
# async
results = await AsyncDDGS().translate('sun', to="de")
```
[Go To TOP](#TOP)
## 8. suggestions() - suggestions by duckduckgo.com
```python
def suggestions(
keywords,
region: str = "wt-wt",
) -> List[Dict[str, str]]:
"""DuckDuckGo suggestions. Query params: https://duckduckgo.com/params.
Args:
keywords: keywords for query.
region: wt-wt, us-en, uk-en, ru-ru, etc. Defaults to "wt-wt".
Returns:
List of dictionaries with suggestions results.
Raises:
DuckDuckGoSearchException: Base exception for duckduckgo_search errors.
RatelimitException: Inherits from DuckDuckGoSearchException, raised for exceeding API request rate limits.
TimeoutException: Inherits from DuckDuckGoSearchException, raised for API request timeouts.
"""
```
***Example***
```python3
results = DDGS().suggestions("fly")
# async
results = await AsyncDDGS().suggestions('sun')
```
[Go To TOP](#TOP)
Raw data
{
"_id": null,
"home_page": null,
"name": "duckduckgo-search",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "python, duckduckgo",
"author": "deedy5",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/68/b4/3a550fd292ba3460af8813d893d7a801546f22a3a38b7df71cf9e95ad340/duckduckgo_search-5.2.1.tar.gz",
"platform": null,
"description": "![Python >= 3.8](https://img.shields.io/badge/python->=3.8-red.svg) [![](https://badgen.net/github/release/deedy5/duckduckgo_search)](https://github.com/deedy5/duckduckgo_search/releases) [![](https://badge.fury.io/py/duckduckgo-search.svg)](https://pypi.org/project/duckduckgo-search) [![Downloads](https://static.pepy.tech/badge/duckduckgo-search)](https://pepy.tech/project/duckduckgo-search) [![Downloads](https://static.pepy.tech/badge/duckduckgo-search/week)](https://pepy.tech/project/duckduckgo-search)\n# Duckduckgo_search<a name=\"TOP\"></a>\n\nSearch for words, documents, images, videos, news, maps and text translation using the DuckDuckGo.com search engine. Downloading files and images to a local hard drive.\n\n\u26a0\ufe0f Warning: it is better to use AsyncDDGS in asynchronous code</br>\n:bangbang: v5.0 brings breaking changes: all functions are now not generators, but return a list of dictionaries.\n\n## Table of Contents\n* [Install](#install)\n* [CLI version](#cli-version)\n* [Duckduckgo search operators](#duckduckgo-search-operators)\n* [Regions](#regions)\n* [DDGS and AsyncDDGS classes](#ddgs-and-asyncddgs-classes)\n* [Proxies](#proxies)\n* [Exceptions](#exceptions)\n* [1. text() - text search](#1-text---text-search-by-duckduckgocom)\n* [2. answers() - instant answers](#2-answers---instant-answers-by-duckduckgocom)\n* [3. images() - image search](#3-images---image-search-by-duckduckgocom)\n* [4. videos() - video search](#4-videos---video-search-by-duckduckgocom)\n* [5. news() - news search](#5-news---news-search-by-duckduckgocom)\n* [6. maps() - map search](#6-maps---map-search-by-duckduckgocom)\n* [7. translate() - translation](#7-translate---translation-by-duckduckgocom)\n* [8. suggestions() - suggestions](#8-suggestions---suggestions-by-duckduckgocom)\n\n## Install\n```python\npip install -U duckduckgo_search\n```\n**[Optional]** To use the `text` function with `backend='html'` or `backend='lite'`:\n```python\npip install -U duckduckgo_search[lxml]\n```\n\n## CLI version\n\n```python3\nddgs --help\n```\nor\n```python3\npython -m duckduckgo_search --help\n```\n\nCLI examples:\n```python3\n# text search\nddgs text -k \"axon regeneration\"\n# find and download pdf files via proxy (example: Tor browser)\nddgs text -k \"neuroscience filetype:pdf\" -r wt-wt -m 50 -d -p socks5://localhost:9150\n# find and download images\nddgs images -k \"gaz 14 chaika\" -r ru-ru -type photo -m 500 -d\n# get latest news and save to csv\nddgs news -k \"hubble telescope\" -m 50 -o csv\n```\n[Go To TOP](#TOP)\n\n## Duckduckgo search operators\n\n| Keywords example |\tResult|\n| --- | --- |\n| cats dogs |\tResults about cats or dogs |\n| \"cats and dogs\" |\tResults for exact term \"cats and dogs\". If no results are found, related results are shown. |\n| cats -dogs |\tFewer dogs in results |\n| cats +dogs |\tMore dogs in results |\n| cats filetype:pdf |\tPDFs about cats. Supported file types: pdf, doc(x), xls(x), ppt(x), html |\n| dogs site:example.com |\tPages about dogs from example.com |\n| cats -site:example.com |\tPages about cats, excluding example.com |\n| intitle:dogs |\tPage title includes the word \"dogs\" |\n| inurl:cats |\tPage url includes the word \"cats\" |\n\n[Go To TOP](#TOP)\n\n## Regions\n<details>\n <summary>expand</summary>\n\n xa-ar for Arabia\n xa-en for Arabia (en)\n ar-es for Argentina\n au-en for Australia\n at-de for Austria\n be-fr for Belgium (fr)\n be-nl for Belgium (nl)\n br-pt for Brazil\n bg-bg for Bulgaria\n ca-en for Canada\n ca-fr for Canada (fr)\n ct-ca for Catalan\n cl-es for Chile\n cn-zh for China\n co-es for Colombia\n hr-hr for Croatia\n cz-cs for Czech Republic\n dk-da for Denmark\n ee-et for Estonia\n fi-fi for Finland\n fr-fr for France\n de-de for Germany\n gr-el for Greece\n hk-tzh for Hong Kong\n hu-hu for Hungary\n in-en for India\n id-id for Indonesia\n id-en for Indonesia (en)\n ie-en for Ireland\n il-he for Israel\n it-it for Italy\n jp-jp for Japan\n kr-kr for Korea\n lv-lv for Latvia\n lt-lt for Lithuania\n xl-es for Latin America\n my-ms for Malaysia\n my-en for Malaysia (en)\n mx-es for Mexico\n nl-nl for Netherlands\n nz-en for New Zealand\n no-no for Norway\n pe-es for Peru\n ph-en for Philippines\n ph-tl for Philippines (tl)\n pl-pl for Poland\n pt-pt for Portugal\n ro-ro for Romania\n ru-ru for Russia\n sg-en for Singapore\n sk-sk for Slovak Republic\n sl-sl for Slovenia\n za-en for South Africa\n es-es for Spain\n se-sv for Sweden\n ch-de for Switzerland (de)\n ch-fr for Switzerland (fr)\n ch-it for Switzerland (it)\n tw-tzh for Taiwan\n th-th for Thailand\n tr-tr for Turkey\n ua-uk for Ukraine\n uk-en for United Kingdom\n us-en for United States\n ue-es for United States (es)\n ve-es for Venezuela\n vn-vi for Vietnam\n wt-wt for No region\n___\n</details>\n\n[Go To TOP](#TOP)\n\n\n## DDGS and AsyncDDGS classes\n\nThe DDGS and AsyncDDGS classes are used to retrieve search results from DuckDuckGo.com.\nTo use the AsyncDDGS class, you can perform asynchronous operations using Python's asyncio library.\nTo initialize an instance of the DDGS or AsyncDDGS classes, you can provide the following optional arguments:\n```python3\nclass DDGS:\n \"\"\"DuckDuckgo_search class to get search results from duckduckgo.com\n\n Args:\n headers (dict, optional): Dictionary of headers for the HTTP client. Defaults to None.\n proxies (Union[dict, str], optional): Proxies for the HTTP client (can be dict or str). Defaults to None.\n timeout (int, optional): Timeout value for the HTTP client. Defaults to 10.\n \"\"\"\n```\n\nHere is an example of initializing the DDGS class. \n```python3\nfrom duckduckgo_search import DDGS\n\nresults = DDGS().text(\"python programming\", max_results=5)\nprint(results)\n```\nHere is an example of initializing the AsyncDDGS class:\n```python3\nimport asyncio\nimport logging\n\nfrom duckduckgo_search import AsyncDDGS\n\nasync def aget_results(word):\n results = await AsyncDDGS(proxies=None).text(word, max_results=100)\n return results\n\nasync def main():\n words = [\"sun\", \"earth\", \"moon\"]\n tasks = [aget_results(w) for w in words]\n results = await asyncio.gather(*tasks)\n print(results)\n\nif __name__ == \"__main__\":\n logging.basicConfig(level=logging.DEBUG)\n asyncio.run(main())\n```\n\n[Go To TOP](#TOP)\n\n## Proxies\nProxy can be specified as a dictionary or just a string\n```python\nproxies = {\"http\": \"socks5://localhost:9150\", \"https\": \"socks5://localhost:9150\"}\nproxies = \"socks5://localhost:9150\"\n```\nUse a proxy that changes ip on each request. Otherwise, use a new proxy with each DDGS or AsyncDDGS initialization.\n\n*1. The easiest way. Launch the Tor Browser*\n```python3\nddgs = DDGS(proxies=\"socks5://localhost:9150\", timeout=20)\nresults = ddgs.text(\"something you need\", max_results=50)\n```\n*2. Use any proxy server* (*example with [iproyal rotating residential proxies](https://iproyal.com?r=residential_proxies)*)\n```python3\nddgs = DDGS(proxies=\"socks5://user:password@geo.iproyal.com:32325\", timeout=20)\nresults = ddgs.text(\"something you need\", max_results=50)\n```\n\n[Go To TOP](#TOP)\n\n## Exceptions\n\nExceptions:\n- `DuckDuckGoSearchException`: Base exception for duckduckgo_search errors.\n- `RatelimitException`: Inherits from DuckDuckGoSearchException, raised for exceeding API request rate limits.\n- `TimeoutException`: Inherits from DuckDuckGoSearchException, raised for API request timeouts.\n\n \n[Go To TOP](#TOP)\n\n## 1. text() - text search by duckduckgo.com\n\n```python\ndef text(\n keywords: str,\n region: str = \"wt-wt\",\n safesearch: str = \"moderate\",\n timelimit: Optional[str] = None,\n backend: str = \"api\",\n max_results: Optional[int] = None,\n) -> List[Dict[str, str]]:\n \"\"\"DuckDuckGo text search generator. Query params: https://duckduckgo.com/params.\n\n Args:\n keywords: keywords for query.\n region: wt-wt, us-en, uk-en, ru-ru, etc. Defaults to \"wt-wt\".\n safesearch: on, moderate, off. Defaults to \"moderate\".\n timelimit: d, w, m, y. Defaults to None.\n backend: api, html, lite. Defaults to api.\n api - collect data from https://duckduckgo.com,\n html - collect data from https://html.duckduckgo.com,\n lite - collect data from https://lite.duckduckgo.com.\n max_results: max number of results. If None, returns results only from the first response. Defaults to None.\n\n Returns:\n List of dictionaries with search results.\n\n Raises:\n DuckDuckGoSearchException: Base exception for duckduckgo_search errors.\n RatelimitException: Inherits from DuckDuckGoSearchException, raised for exceeding API request rate limits.\n TimeoutException: Inherits from DuckDuckGoSearchException, raised for API request timeouts.\n \"\"\"\n```\n***Example***\n```python\nresults = DDGS().text('live free or die', region='wt-wt', safesearch='off', timelimit='y', max_results=10)\n# Searching for pdf files\nresults = DDGS().text('russia filetype:pdf', region='wt-wt', safesearch='off', timelimit='y', max_results=10)\n\n# async\nresults = await AsyncDDGS().text('sun', region='wt-wt', safesearch='off', timelimit='y', max_results=10)\n```\n\n[Go To TOP](#TOP)\n\n## 2. answers() - instant answers by duckduckgo.com\n\n```python\ndef answers(keywords: str) -> List[Dict[str, str]]:\n \"\"\"DuckDuckGo instant answers. Query params: https://duckduckgo.com/params.\n \n Args:\n keywords: keywords for query,\n \n Returns:\n List of dictionaries with instant answers results.\n \n Raises:\n DuckDuckGoSearchException: Base exception for duckduckgo_search errors.\n RatelimitException: Inherits from DuckDuckGoSearchException, raised for exceeding API request rate limits.\n TimeoutException: Inherits from DuckDuckGoSearchException, raised for API request timeouts.\n \"\"\"\n```\n***Example***\n```python\nresults = DDGS().answers(\"sun\")\n\n# async\nresults = await AsyncDDGS().answers(\"sun\")\n```\n\n[Go To TOP](#TOP)\n\n## 3. images() - image search by duckduckgo.com\n\n```python\ndef images(\n keywords: str,\n region: str = \"wt-wt\",\n safesearch: str = \"moderate\",\n timelimit: Optional[str] = None,\n size: Optional[str] = None,\n color: Optional[str] = None,\n type_image: Optional[str] = None,\n layout: Optional[str] = None,\n license_image: Optional[str] = None,\n max_results: Optional[int] = None,\n) -> List[Dict[str, str]]:\n \"\"\"DuckDuckGo images search. Query params: https://duckduckgo.com/params.\n \n Args:\n keywords: keywords for query.\n region: wt-wt, us-en, uk-en, ru-ru, etc. Defaults to \"wt-wt\".\n safesearch: on, moderate, off. Defaults to \"moderate\".\n timelimit: Day, Week, Month, Year. Defaults to None.\n size: Small, Medium, Large, Wallpaper. Defaults to None.\n color: color, Monochrome, Red, Orange, Yellow, Green, Blue,\n Purple, Pink, Brown, Black, Gray, Teal, White. Defaults to None.\n type_image: photo, clipart, gif, transparent, line.\n Defaults to None.\n layout: Square, Tall, Wide. Defaults to None.\n license_image: any (All Creative Commons), Public (PublicDomain),\n Share (Free to Share and Use), ShareCommercially (Free to Share and Use Commercially),\n Modify (Free to Modify, Share, and Use), ModifyCommercially (Free to Modify, Share, and\n Use Commercially). Defaults to None.\n max_results: max number of results. If None, returns results only from the first response. Defaults to None.\n \n Returns:\n List of dictionaries with images search results.\n \n Raises:\n DuckDuckGoSearchException: Base exception for duckduckgo_search errors.\n RatelimitException: Inherits from DuckDuckGoSearchException, raised for exceeding API request rate limits.\n TimeoutException: Inherits from DuckDuckGoSearchException, raised for API request timeouts.\n \"\"\"\n```\n***Example***\n```python\nresults = DDGS().images(\n keywords=\"butterfly\",\n region=\"wt-wt\",\n safesearch=\"off\",\n size=None,\n color=\"Monochrome\",\n type_image=None,\n layout=None,\n license_image=None,\n max_results=100,\n)\n\n# async\nresults = await AsyncDDGS().images('sun', region='wt-wt', safesearch='off', max_results=20)\n```\n\n[Go To TOP](#TOP)\n\n## 4. videos() - video search by duckduckgo.com\n\n```python\ndef videos(\n keywords: str,\n region: str = \"wt-wt\",\n safesearch: str = \"moderate\",\n timelimit: Optional[str] = None,\n resolution: Optional[str] = None,\n duration: Optional[str] = None,\n license_videos: Optional[str] = None,\n max_results: Optional[int] = None,\n) -> List[Dict[str, str]]:\n \"\"\"DuckDuckGo videos search. Query params: https://duckduckgo.com/params.\n \n Args:\n keywords: keywords for query.\n region: wt-wt, us-en, uk-en, ru-ru, etc. Defaults to \"wt-wt\".\n safesearch: on, moderate, off. Defaults to \"moderate\".\n timelimit: d, w, m. Defaults to None.\n resolution: high, standart. Defaults to None.\n duration: short, medium, long. Defaults to None.\n license_videos: creativeCommon, youtube. Defaults to None.\n max_results: max number of results. If None, returns results only from the first response. Defaults to None.\n \n Returns:\n List of dictionaries with videos search results.\n \n Raises:\n DuckDuckGoSearchException: Base exception for duckduckgo_search errors.\n RatelimitException: Inherits from DuckDuckGoSearchException, raised for exceeding API request rate limits.\n TimeoutException: Inherits from DuckDuckGoSearchException, raised for API request timeouts.\n \"\"\"\n```\n***Example***\n```python\nresults = DDGS().videos(\n keywords=\"cars\",\n region=\"wt-wt\",\n safesearch=\"off\",\n timelimit=\"w\",\n resolution=\"high\",\n duration=\"medium\",\n max_results=100,\n)\n\n# async\nresults = await AsyncDDGS().videos('sun', region='wt-wt', safesearch='off', timelimit='y', max_results=10)\n```\n\n[Go To TOP](#TOP)\n\n## 5. news() - news search by duckduckgo.com\n\n```python\ndef news(\n keywords: str,\n region: str = \"wt-wt\",\n safesearch: str = \"moderate\",\n timelimit: Optional[str] = None,\n max_results: Optional[int] = None,\n) -> List[Dict[str, str]]:\n \"\"\"DuckDuckGo news search. Query params: https://duckduckgo.com/params.\n \n Args:\n keywords: keywords for query.\n region: wt-wt, us-en, uk-en, ru-ru, etc. Defaults to \"wt-wt\".\n safesearch: on, moderate, off. Defaults to \"moderate\".\n timelimit: d, w, m. Defaults to None.\n max_results: max number of results. If None, returns results only from the first response. Defaults to None.\n \n Returns:\n List of dictionaries with news search results.\n \n Raises:\n DuckDuckGoSearchException: Base exception for duckduckgo_search errors.\n RatelimitException: Inherits from DuckDuckGoSearchException, raised for exceeding API request rate limits.\n TimeoutException: Inherits from DuckDuckGoSearchException, raised for API request timeouts.\n \"\"\"\n```\n***Example***\n```python\nresults = DDGS().news(keywords=\"sun\", region=\"wt-wt\", safesearch=\"off\", timelimit=\"m\", max_results=20)\n\n# async\nresults = await AsyncDDGS().news('sun', region='wt-wt', safesearch='off', timelimit='d', max_results=10)\n```\n\n[Go To TOP](#TOP)\n\n## 6. maps() - map search by duckduckgo.com\n\n```python\ndef maps(\n keywords,\n place: Optional[str] = None,\n street: Optional[str] = None,\n city: Optional[str] = None,\n county: Optional[str] = None,\n state: Optional[str] = None,\n country: Optional[str] = None,\n postalcode: Optional[str] = None,\n latitude: Optional[str] = None,\n longitude: Optional[str] = None,\n radius: int = 0,\n max_results: Optional[int] = None,\n) -> List[Dict[str, str]]:\n \"\"\"DuckDuckGo maps search. Query params: https://duckduckgo.com/params.\n \n Args:\n keywords: keywords for query\n place: if set, the other parameters are not used. Defaults to None.\n street: house number/street. Defaults to None.\n city: city of search. Defaults to None.\n county: county of search. Defaults to None.\n state: state of search. Defaults to None.\n country: country of search. Defaults to None.\n postalcode: postalcode of search. Defaults to None.\n latitude: geographic coordinate (north-south position). Defaults to None.\n longitude: geographic coordinate (east-west position); if latitude and\n longitude are set, the other parameters are not used. Defaults to None.\n radius: expand the search square by the distance in kilometers. Defaults to 0.\n max_results: max number of results. If None, returns results only from the first response. Defaults to None.\n \n Returns:\n List of dictionaries with maps search results.\n \n Raises:\n DuckDuckGoSearchException: Base exception for duckduckgo_search errors.\n RatelimitException: Inherits from DuckDuckGoSearchException, raised for exceeding API request rate limits.\n TimeoutException: Inherits from DuckDuckGoSearchException, raised for API request timeouts.\n \"\"\"\n```\n***Example***\n```python\nresults = DDGS().maps(\"school\", place=\"Uganda\", max_results=50)\n\n# async\nresults = await AsyncDDGS().maps('shop', place=\"Baltimor\", max_results=10)\n```\n\n[Go To TOP](#TOP)\n\n## 7. translate() - translation by duckduckgo.com\n\n```python\ndef translate(\n self,\n keywords: str,\n from_: Optional[str] = None,\n to: str = \"en\",\n) -> List[Dict[str, str]]:\n \"\"\"DuckDuckGo translate.\n \n Args:\n keywords: string or list of strings to translate.\n from_: translate from (defaults automatically). Defaults to None.\n to: what language to translate. Defaults to \"en\".\n \n Returns:\n List od dictionaries with translated keywords.\n \n Raises:\n DuckDuckGoSearchException: Base exception for duckduckgo_search errors.\n RatelimitException: Inherits from DuckDuckGoSearchException, raised for exceeding API request rate limits.\n TimeoutException: Inherits from DuckDuckGoSearchException, raised for API request timeouts.\n \"\"\"\n```\n***Example***\n```python\nkeywords = 'school'\n# also valid\nkeywords = ['school', 'cat']\nresults = DDGS().translate(keywords, to=\"de\")\n\n# async\nresults = await AsyncDDGS().translate('sun', to=\"de\")\n```\n\n[Go To TOP](#TOP)\n\n## 8. suggestions() - suggestions by duckduckgo.com\n\n```python\ndef suggestions(\n keywords,\n region: str = \"wt-wt\",\n) -> List[Dict[str, str]]:\n \"\"\"DuckDuckGo suggestions. Query params: https://duckduckgo.com/params.\n \n Args:\n keywords: keywords for query.\n region: wt-wt, us-en, uk-en, ru-ru, etc. Defaults to \"wt-wt\".\n \n Returns:\n List of dictionaries with suggestions results.\n \n Raises:\n DuckDuckGoSearchException: Base exception for duckduckgo_search errors.\n RatelimitException: Inherits from DuckDuckGoSearchException, raised for exceeding API request rate limits.\n TimeoutException: Inherits from DuckDuckGoSearchException, raised for API request timeouts.\n \"\"\"\n```\n***Example***\n```python3\nresults = DDGS().suggestions(\"fly\")\n\n# async\nresults = await AsyncDDGS().suggestions('sun')\n```\n\n[Go To TOP](#TOP)\n",
"bugtrack_url": null,
"license": "MIT License",
"summary": "Search for words, documents, images, news, maps and text translation using the DuckDuckGo.com search engine.",
"version": "5.2.1",
"project_urls": {
"Homepage": "https://github.com/deedy5/duckduckgo_search"
},
"split_keywords": [
"python",
" duckduckgo"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "51dc4bae2c921c36e0b34863d8cb23e196a3b3332d034417498b49091eabb18d",
"md5": "4a3ca68bf6ce36790d389322006fda2a",
"sha256": "3cd75f3605f53c7f753b3f948374ddd8b94b0b7e0c453b5824912d8aa8e3f64d"
},
"downloads": -1,
"filename": "duckduckgo_search-5.2.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "4a3ca68bf6ce36790d389322006fda2a",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 21389,
"upload_time": "2024-03-28T20:29:07",
"upload_time_iso_8601": "2024-03-28T20:29:07.519459Z",
"url": "https://files.pythonhosted.org/packages/51/dc/4bae2c921c36e0b34863d8cb23e196a3b3332d034417498b49091eabb18d/duckduckgo_search-5.2.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "68b43a550fd292ba3460af8813d893d7a801546f22a3a38b7df71cf9e95ad340",
"md5": "469b172bc02dc84f260ef91cfe4c0d38",
"sha256": "01043cebcdbac6b79cf42ea955d9330278a7a7be666c80b872932c2c6a9de1a4"
},
"downloads": -1,
"filename": "duckduckgo_search-5.2.1.tar.gz",
"has_sig": false,
"md5_digest": "469b172bc02dc84f260ef91cfe4c0d38",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 25031,
"upload_time": "2024-03-28T20:29:10",
"upload_time_iso_8601": "2024-03-28T20:29:10.134955Z",
"url": "https://files.pythonhosted.org/packages/68/b4/3a550fd292ba3460af8813d893d7a801546f22a3a38b7df71cf9e95ad340/duckduckgo_search-5.2.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-03-28 20:29:10",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "deedy5",
"github_project": "duckduckgo_search",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "duckduckgo-search"
}