duckduckgo-search 8.1.1
pip install duckduckgo-search
Released:
Search for words, documents, images, news, maps and text translation using the DuckDuckGo.com search engine.
Navigation
Verified details
These details have been verified by PyPIMaintainers
๐ Avatar for deedy5 from gravatar.comdeedy5
Unverified details
These details have not been verified by PyPIProject links
Meta
- License: MIT License (MIT License)
- Author: deedy5
- Tags python , duckduckgo
- Requires: Python >=3.9
-
Provides-Extra:
dev
Classifiers
- Development Status
- License
- Operating System
- Programming Language
- Topic
Project description
:warning: This package (duckduckgo_search) has been renamed to ddgs! Use pip install ddgs instead.
New package: https://pypi.org/project/ddgs/
๐ Python >= 3.9
๐ Image
๐ Image
Duckduckgo_search
Search for text, news, images and videos using the DuckDuckGo.com search engine.
:bangbang: AI chat moved to duckai package
Table of Contents
- Install
- CLI version
- Duckduckgo search operators
- Regions
- DDGS class
- Proxy
- Exceptions
- 1. text()
- 2. images()
- 3. videos()
- 4. news()
- Disclaimer
Install
pip install -U duckduckgo_search
CLI version
ddgs --help
CLI examples:
# text search ddgs text -k "Assyrian siege of Jerusalem" # find and download pdf files via proxy ddgs text -k "Economics in one lesson filetype:pdf" -r wt-wt -m 50 -p https://1.2.3.4:1234 -d -dd economics_reading # using Tor Browser as a proxy (`tb` is an alias for `socks5://127.0.0.1:9150`) ddgs text -k "'The history of the Standard Oil Company' filetype:doc" -m 50 -d -p tb # find and save to csv ddgs text -k "'neuroscience exploring the brain' filetype:pdf" -m 70 -o neuroscience_list.csv # don't verify SSL when making the request ddgs text -k "Mississippi Burning" -v false # find and download images ddgs images -k "beware of false prophets" -r wt-wt -type photo -m 500 -d # get news for the last day and save to json ddgs news -k "sanctions" -m 100 -t d -o json
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" |
Regions
DDGS class
The DDGS classes is used to retrieve search results from DuckDuckGo.com.
classDDGS: """DuckDuckgo_search class to get search results from duckduckgo.com Args: headers (dict, optional): Dictionary of headers for the HTTP client. Defaults to None. proxy (str, optional): proxy for the HTTP client, supports http/https/socks5 protocols. example: "http://user:pass@example.com:3128". Defaults to None. timeout (int, optional): Timeout value for the HTTP client. Defaults to 10. verify (bool): SSL verification when making the request. Defaults to True. """
Here is an example of initializing the DDGS class.
fromduckduckgo_searchimport DDGS results = DDGS().text("python programming", max_results=5) print(results)
Proxy
Package supports http/https/socks proxies. Example: http://user:pass@example.com:3128.
Use a rotating proxy. Otherwise, use a new proxy with each DDGS class initialization.
1. The easiest way. Launch the Tor Browser
ddgs = DDGS(proxy="tb", timeout=20) # "tb" is an alias for "socks5://127.0.0.1:9150" results = ddgs.text("something you need", max_results=50)
2. Use any proxy server (example with iproyal rotating residential proxies)
ddgs = DDGS(proxy="socks5h://user:password@geo.iproyal.com:32325", timeout=20) results = ddgs.text("something you need", max_results=50)
3. The proxy can also be set using the DDGS_PROXY environment variable.
export DDGS_PROXY="socks5h://user:password@geo.iproyal.com:32325"
Exceptions
fromduckduckgo_search.exceptionsimport ( ConversationLimitException, DuckDuckGoSearchException, RatelimitException, TimeoutException, )
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.ConversationLimitException: Inherits from DuckDuckGoSearchException, raised for conversation limit during API requests to AI endpoint.
1. text()
deftext( 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 generator. Query params: https://duckduckgo.com/params. Args: keywords: keywords for query. region: us-en, uk-en, ru-ru, etc. Defaults to None. safesearch: on, moderate, off. Defaults to "moderate". timelimit: d, w, m, y. Defaults to None. backend: auto, html, lite. Defaults to auto. auto - try all backends in random order, html - collect data from https://html.duckduckgo.com, lite - collect data from https://lite.duckduckgo.com, bing - collect data from https://www.bing.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. """
Example
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) print(results) [ { "title": "News, sport, celebrities and gossip | The Sun", "href": "https://www.thesun.co.uk/", "body": "Get the latest news, exclusives, sport, celebrities, showbiz, politics, business and lifestyle from The Sun", }, ... ]
2. images()
defimages( keywords: str, region: str = "us-en", safesearch: str = "moderate", timelimit: str | None = None, size: str | None = None, color: str | None = None, type_image: str | None = None, layout: str | None = None, license_image: str | None = None, max_results: int | None = None, ) -> list[dict[str, str]]: """DuckDuckGo images search. Query params: https://duckduckgo.com/params. Args: keywords: keywords for query. region: us-en, uk-en, ru-ru, etc. Defaults to "us-en". 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. """
Example
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, ) print(images) [ { "title": "File:The Sun by the Atmospheric Imaging Assembly of NASA's Solar ...", "image": "https://upload.wikimedia.org/wikipedia/commons/b/b4/The_Sun_by_the_Atmospheric_Imaging_Assembly_of_NASA's_Solar_Dynamics_Observatory_-_20100819.jpg", "thumbnail": "https://tse4.mm.bing.net/th?id=OIP.lNgpqGl16U0ft3rS8TdFcgEsEe&pid=Api", "url": "https://en.wikipedia.org/wiki/File:The_Sun_by_the_Atmospheric_Imaging_Assembly_of_NASA's_Solar_Dynamics_Observatory_-_20100819.jpg", "height": 3860, "width": 4044, "source": "Bing", }, ... ]
3. videos()
defvideos( keywords: str, region: str = "us-en", safesearch: str = "moderate", timelimit: str | None = None, resolution: str | None = None, duration: str | None = None, license_videos: str | None = None, max_results: int | None = None, ) -> list[dict[str, str]]: """DuckDuckGo videos search. Query params: https://duckduckgo.com/params. Args: keywords: keywords for query. region: us-en, uk-en, ru-ru, etc. Defaults to "us-en". 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. """
Example
results = DDGS().videos( keywords="cars", region="wt-wt", safesearch="off", timelimit="w", resolution="high", duration="medium", max_results=100, ) print(results) [ { "content": "https://www.youtube.com/watch?v=6901-C73P3g", "description": "Watch the Best Scenes of popular Tamil Serial #Meena that airs on Sun TV. Watch all Sun TV serials immediately after the TV telecast on Sun NXT app. *Free for Indian Users only Download here: Android - http://bit.ly/SunNxtAdroid iOS: India - http://bit.ly/sunNXT Watch on the web - https://www.sunnxt.com/ Two close friends, Chidambaram ...", "duration": "8:22", "embed_html": '<iframe width="1280" height="720" src="https://www.youtube.com/embed/6901-C73P3g?autoplay=1" frameborder="0" allowfullscreen></iframe>', "embed_url": "https://www.youtube.com/embed/6901-C73P3g?autoplay=1", "image_token": "6c070b5f0e24e5972e360d02ddeb69856202f97718ea6c5d5710e4e472310fa3", "images": { "large": "https://tse4.mm.bing.net/th?id=OVF.JWBFKm1u%2fHd%2bz2e1GitsQw&pid=Api", "medium": "https://tse4.mm.bing.net/th?id=OVF.JWBFKm1u%2fHd%2bz2e1GitsQw&pid=Api", "motion": "", "small": "https://tse4.mm.bing.net/th?id=OVF.JWBFKm1u%2fHd%2bz2e1GitsQw&pid=Api", }, "provider": "Bing", "published": "2024-07-03T05:30:03.0000000", "publisher": "YouTube", "statistics": {"viewCount": 29059}, "title": "Meena - Best Scenes | 02 July 2024 | Tamil Serial | Sun TV", "uploader": "Sun TV", }, ... ]
4. news()
defnews( keywords: str, region: str = "us-en", safesearch: str = "moderate", timelimit: str | None = None, max_results: int | None = None, ) -> list[dict[str, str]]: """DuckDuckGo news search. Query params: https://duckduckgo.com/params. Args: keywords: keywords for query. region: us-en, uk-en, ru-ru, etc. Defaults to "us-en". 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. """
Example
results = DDGS().news(keywords="sun", region="wt-wt", safesearch="off", timelimit="m", max_results=20) print(results) [ { "date": "2024-07-03T16:25:22+00:00", "title": "Murdoch's Sun Endorses Starmer's Labour Day Before UK Vote", "body": "Rupert Murdoch's Sun newspaper endorsed Keir Starmer and his opposition Labour Party to win the UK general election, a dramatic move in the British media landscape that illustrates the country's shifting political sands.", "url": "https://www.msn.com/en-us/money/other/murdoch-s-sun-endorses-starmer-s-labour-day-before-uk-vote/ar-BB1plQwl", "image": "https://img-s-msn-com.akamaized.net/tenant/amp/entityid/BB1plZil.img?w=2000&h=1333&m=4&q=79", "source": "Bloomberg on MSN.com", }, ... ]
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.
Project details
Verified details
These details have been verified by PyPIMaintainers
๐ Avatar for deedy5 from gravatar.comdeedy5
Unverified details
These details have not been verified by PyPIProject links
Meta
- License: MIT License (MIT License)
- Author: deedy5
- Tags python , duckduckgo
- Requires: Python >=3.9
-
Provides-Extra:
dev
Classifiers
- Development Status
- License
- Operating System
- Programming Language
- Topic
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file duckduckgo_search-8.1.1.tar.gz.
File metadata
- Download URL: duckduckgo_search-8.1.1.tar.gz
- Upload date:
- Size: 22.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9da91c9eb26a17e016ea1da26235d40404b46b0565ea86d75a9f78cc9441f935
|
|
| MD5 |
65f29c974f8714929471dbd4ba357936
|
|
| BLAKE2b-256 |
10ef07791a05751e6cc9de1dd49fb12730259ee109b18e6d097e25e6c32d5617
|
File details
Details for the file duckduckgo_search-8.1.1-py3-none-any.whl.
File metadata
- Download URL: duckduckgo_search-8.1.1-py3-none-any.whl
- Upload date:
- Size: 18.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f48adbb06626ee05918f7e0cef3a45639e9939805c4fc179e68c48a12f1b5062
|
|
| MD5 |
36ce29d101054d411ec9bf35042c1d55
|
|
| BLAKE2b-256 |
db72c027b3b488b1010cf71670032fcf7e681d44b81829d484bb04e31a949a8d
|
