Skip to main content

PyPI package CI Status Coverage

DuckDuckPy is a Python library for querying DuckDuckGo API and render results either to Python dictionary or namedtuple.

Features

  • Uses standard library only

  • Works on Python 2.6+ and 3.3+

  • Unit test coverage 100%

  • SSL and unicode support

  • Licensed under MIT license

Installation

You can install DuckDuckPy either via the Python Package Index (PyPI) or from source.

To install using pip:

$ pip install duckduckpy

To install using easy_install:

$ easy_install duckduckpy

To install from sources you can download the latest version of DuckDuckPy either from PyPI or GitHub, extract archive contents and run following command from the source directory:

$ python setup.py install

Latest upstream version can be installed directly from the git repository:

$ pip install git+https://github.com/ivankliuk/duckduckpy.git

API description

query(query_string, secure=False, container=u'namedtuple', verbose=False,
      user_agent=u'duckduckpy 0.2', no_redirect=False, no_html=False,
      skip_disambig=False)

Generates and sends a query to DuckDuckGo API.

Arguments:

query_string

Query to be passed to DuckDuckGo API.

secure

Use secure SSL/TLS connection. Default - False. Syntactic sugar is secure_query function which is passed the same parameters.

container

Indicates how dict-like objects are serialized. There are two possible options: namedtuple and dict. If ‘namedtuple’ is passed the objects will be serialized to namedtuple instance of certain class. If ‘dict’ is passed the objects won’t be deserialized. Default value: ‘namedtuple’.

verbose

Don’t raise any exception if error occurs. Default value: False.

user_agent

User-Agent header of HTTP requests to DuckDuckGo API. Default value: ‘duckduckpy 0.2’

no_redirect

Skip HTTP redirects (for !bang commands). Default value: False.

no_html

Remove HTML from text, e.g. bold and italics. Default value: False.

skip_disambig

Skip disambiguation (D) Type. Default value: False.

Raises:

DuckDuckDeserializeError

JSON serialization failed.

DuckDuckConnectionError

Something went wrong with httplib operation.

DuckDuckArgumentError

Passed argument is wrong.

Returns:

Container depends on container parameter. Each field in the response is converted to the so-called snake case.

Usage

>>> from duckduckpy import query
>>> response = query('Python') # namedtuple is used as a container
>>> response
Response(redirect=u'', definition=u'', image_width=0, ...}
>>> type(response)
<class 'duckduckpy.api.Response'>
>>> response.related_topics[0]
Result(first_url=u'https://duckduckgo.com/Python', text=...)
>>> type(response.related_topics[0])
<class 'duckduckpy.api.Result'>

>>> response = query('Python', container='dict') # dict as the container
>>> type(response)
<type 'dict'>
>>> response
{u'abstract': u'', u'results': [], u'image_is_logo': 0, ...}
>>> type(response['related_topics'][0])
<type 'dict'>
>>> response['related_topics'][0]
{u'first_url': u'https://duckduckgo.com/Python', u'text': ...}

TODO

  • SSL certificate checking

Release files for duckduckpy 0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for duckduckpy 0.2
File Size Uploaded
duckduckpy-0.2.tar.bz2 7.1 kB Details

Release files / duckduckpy-0.2.tar.bz2

Download URL duckduckpy-0.2.tar.bz2
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
608c2972efc375d3af88fef12a182e62bd8e3f971fc1e51877a2f636599e18b8
BLAKE2b-256 checksum
How to use checksums
e07ab186c3e372217edf3573844cdf5d9c22f11d147ec8d46f04982b40b4f4f1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.2 This release

1 release file

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page