A simple module for searching on DuckDuckGo
Project description
A simple Python module for searching on DuckDuckGo.
Installation
Duckpy can be installed using pip with this command
pip install -U duckpy
Alternatively, you can install the most recent version from git
pip install -U git+https://github.com/AmanoTeam/duckpy
If you are using Debian or Ubuntu, you can install with this command (Currently only in Debian Unstable and Ubuntu 20.10+)
sudo apt install python3-duckpy
Usage
from duckpy import Client
client = Client()
results = client.search("Python Wikipedia")
# Prints first result title
print(results[0].title)
# Prints first result URL
print(results[0].url)
# Prints first result description
print(results[0].description)
We also provide an asynchronous version inside the AsyncClient
class
import asyncio
from duckpy import AsyncClient
client = AsyncClient()
async def get_results():
results = await client.search("Python Wikipedia")
# Prints first result title
print(results[0].title)
# Prints first result URL
print(results[0].url)
# Prints first result description
print(results[0].description)
loop = asyncio.get_event_loop()
loop.run_until_complete(get_results())
The result
Python (programming language) - Wikipedia
https://en.wikipedia.org/wiki/Python_(programming_language)
Python is an interpreted, high-level, general-purpose programming language. Created by Guido van Rossum and first released in 1991...
Advanced usage
You can also set up proxies or set up custom User-Agent strings depending on your needs.
Setting up proxies
DuckDuckGo may temporarily block your request IP or return empty results, especially if you are using the library for scraping, bots and other stuff that generate many requests. This is not a duckpy issue and can be prevented using proxies.
You can pass a list with proxies in the Client object, then duckpy will use these proxies to make requests:
import duckpy
client = duckpy.Client(proxies=['http://123.45.67.89:80', 'https://98.76.54.32:443'])
If you pass more than one proxy, they will be randomly chosen every time you use the .search() method.
Setting up custom User-Agents
import duckpy
user_agents = [
"Mozilla/5.0 (X11; Linux x86_64; rv:79.0) Gecko/20100101 Firefox/79.0",
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.105 Safari/537.36"
]
client = duckpy.Client(default_user_agents=user_agents)
Again, if you pass more than one User-Agent, they will be randomly chosen every time you use the .search() method.
Disclaimer
We are not affiliated, associated, authorized, endorsed by, or in any way officially connected with DuckDuckGo, or any of its subsidiaries or its affiliates. The official DuckDuckGo website can be found at https://duckduckgo.com.
Project details
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
File details
Details for the file duckpy-3.2.0.tar.gz
.
File metadata
- Download URL: duckpy-3.2.0.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7b3ac88521bd71e610a10d2d2b7c9b39bc7669348fc9752c8d0b3ae1ea7dc000 |
|
MD5 | afea6fef702e8b650b39bc6bfdbda204 |
|
BLAKE2b-256 | 92d80ed92b9f838584ce6f36c205f72eaa449a8141234d3441ea75e93bb52cd9 |
File details
Details for the file duckpy-3.2.0-py3-none-any.whl
.
File metadata
- Download URL: duckpy-3.2.0-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.6.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 63ec931083dce9bece2ef8de161bfbb323d52a73351d80aa383793e89275628b |
|
MD5 | 23dac665c1720a410ae2f37d8a699106 |
|
BLAKE2b-256 | cd8002f8b128ec3c0d196f033d78c06e42c30d25359c3112ddb4bd1435d1806d |