A simple Python library for searching on DuckDuckGo.
Find a file
dependabot[bot] 177e699c13
Update httpx[http2] requirement from <0.19,>=0.14 to >=0.14,<0.24 (#12)
Updates the requirements on [httpx[http2]](https://github.com/encode/httpx) to permit the latest version.
- [Release notes](https://github.com/encode/httpx/releases)
- [Changelog](https://github.com/encode/httpx/blob/master/CHANGELOG.md)
- [Commits](https://github.com/encode/httpx/compare/0.14.0...0.23.0)

---
updated-dependencies:
- dependency-name: httpx[http2]
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-11-11 03:26:32 -03:00
.github Create dependabot config 2020-08-19 02:03:28 -03:00
duckpy chore: setup.py -> pyproject.toml and drop duckpy.aio 2022-11-11 03:19:26 -03:00
.gitignore Add .venv to .gitignore list 2020-08-19 02:33:46 -03:00
LICENSE Add license 2020-06-20 05:22:10 -03:00
pyproject.toml Update httpx[http2] requirement from <0.19,>=0.14 to >=0.14,<0.24 (#12) 2022-11-11 03:26:32 -03:00
README.md 3.2.0: More typing hint support 2020-09-10 02:37:02 -03:00

DuckPy

A simple Python module for searching on DuckDuckGo.

PyPI GitHub

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.