Skip to main content

A simple module for searching on DuckDuckGo

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

duckpy-3.1.0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

duckpy-3.1.0-py3-none-any.whl (4.7 kB view details)

Uploaded Python 3

File details

Details for the file duckpy-3.1.0.tar.gz.

File metadata

  • Download URL: duckpy-3.1.0.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.0.3 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for duckpy-3.1.0.tar.gz
Algorithm Hash digest
SHA256 c1b62ba5d1b7876778d5952011e0a06d5fdf1b4121c5a607d4b7ae2f3b22dac2
MD5 d000498dae0c4c8b2899162e8a253fa8
BLAKE2b-256 049f4ae6bdeddf16e25afcd7331e7b57bbd3cd6cbc7537217ba6def3dcacd371

See more details on using hashes here.

File details

Details for the file duckpy-3.1.0-py3-none-any.whl.

File metadata

  • Download URL: duckpy-3.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/50.0.3 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

File hashes

Hashes for duckpy-3.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f0947c9a8da7cd614424933aeceec830d82fb6997c42216dd5375fe6dc6d8a74
MD5 3be592ea7e86b1f693f797a0b717f4b6
BLAKE2b-256 5e26fd8d448d0826b9af0e81602708294b7d7643264a7c06d4908022bf2dcdf2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page