Skip to main content
.. class:: center

=========
PublicDNS
=========


PublicDNS is a high-perfmrnace, secure, reliable python DNS client `over HTTP/2 and TLS`__.

__ https://developers.google.com/speed/public-dns/docs/dns-over-https

As written in Google DNS-over-HTTPS guide, this offers a variety of features as follows:

- support all RRs
- support DNSSEC validation
- support for IPv4 and IPv6
- can insure against `privacy concerns`__

__ https://https.cio.gov/everything/

Performance
===========

While tranditional DNS client does not support `put multiple questions into a single call`__,
PublicDNS has advantage that it's much faster when dealing with multiple questions, `a big advantage of HTTP/2`__.
Because Google servers also run over QUIC, this also means that performance will be much better if it is implemented.

I recently benchmarked with a small amount of domains, take a look at the result:

.. code-block:: console

- dns.resolver
100%|███| 100/100 [00:32<00:00, 3.97s/it]
dns.resolver * 100 - took 32.5060371872969s
- PublicDNS
100%|███| 100/100 [00:13<00:00, 12.8it/s]
PublicDNS * 100 - took 13.507565873209387s

__ https://groups.google.com/d/msg/comp.protocols.dns.bind/uOWxNkm7AVg/wKtsmudkY1UJ
__ https://istlsfastyet.com/#faq

Installation
============

Install PublicDNS using easy_setup or pip:

.. code-block:: console

pip install publicdns

Example
=======

.. code-block:: python

from publicdns.client import PublicDNS

client = PublicDNS()
result = client.query('www.google.com', 'A')
ip = client.resolve('www.google.com')

To see more usage, just dive into the ``tests`` directory.

API
===

The public API is really simple, totaling only 2 API calls:

* ``query(host, type='A', dnssec=True)``: Do a DNS resolution of the given type for the given hostname. It returns an
instance of ``publicdns.models.DNSResponse``.
* ``resolve(host, type='A', dnssec=True)``: Do a DNS resolution of the given type for the given hostname. While
``query()`` returns an instance of ``publicdns.models.DNSResponse``, ``resolve()`` only return a list of data
like ``['8.8.8.8']``.


Patching
--------

Replace some functions of the standard socket object with publicdns's implementation.

.. code-block:: python

from publicdns.monkey import patch_socket
patch_socket()

Documentation
=============

Until the project is properly documented you will have to rely on the source code. It is rather undocumented now, but
better documentation is under way. On the other hand, the code is quite extensively tested.

Query Limitation
----------------

Google can limit the number of API requests. Please follow `Rate-limiting queries`__ section.

__ https://developers.google.com/speed/public-dns/docs/security#rate_limit

Running tests
=============

PublicDNS has tests. These tests ensure that the code is in a working state. You have to install some external packages to run tests, listed in ``test_requirements.txt``:

.. code-block:: console

$ pip install -r test_requirements.txt

then:

.. code-block:: console

$ py.test

Alternatively, to run them in every supported Python version do:

.. code-block:: console

$ tox

Contributing
===========

1. Create an issue and describe your idea
2. Fork this repo
3. Create your feature branch (``git checkout -b my-new-feature``)
4. Run tests
5. Add a test for your feature
6. Run step 4 again
7. Commit your changes (``git commit -am 'Add some feature'``)
8. Publish the branch (``git push origin my-new-feature``)
9. Create a new Pull Request


License
=======

PublicDNS is released under the `MIT License`__.

__ http://www.opensource.org/licenses/MIT


Metadata

Release files for publicdns 0.1.0

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

Source distribution (sdist)

Source distribution for publicdns 0.1.0
File Size Uploaded
publicdns-0.1.0.tar.gz 7.4 kB Details

Release files / publicdns-0.1.0.tar.gz

Download URL publicdns-0.1.0.tar.gz
Size 7.4 kB
Tags Source
SHA-256 checksum
How to use checksums
1d9f69f734cdf30e8f73b67523fa2a4c3d0a34134d81a827e7eab064e7ba171b
BLAKE2b-256 checksum
How to use checksums
ed16726958106e6a15161af2a6ca3b0c066116e9b7e9a88893b1b26446036b2d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file

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