• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

aiodns/H28-Aug-2016-136104

aiodns.egg-info/H03-May-2022-12388

ChangeLogH A D28-Aug-2016685 4333

LICENSEH A D26-Mar-20141 KiB2116

MANIFEST.inH A D25-Jan-2016125 64

PKG-INFOH A D28-Aug-20164.7 KiB12388

README.rstH A D27-Aug-20162.9 KiB9662

setup.cfgH A D28-Aug-201688 96

setup.pyH A D28-Aug-20161.8 KiB5142

tests.pyH A D27-Aug-20164.9 KiB155112

README.rst

1===============================
2Simple DNS resolver for asyncio
3===============================
4
5.. image:: https://secure.travis-ci.org/saghul/aiodns.png?branch=master
6    :target: http://travis-ci.org/saghul/aiodns
7
8aiodns provides a simple way for doing asynchronous DNS resolutions
9with a synchronous looking interface by using `pycares <https://github.com/saghul/pycares>`_.
10
11
12Example
13=======
14
15::
16
17    import asyncio
18    import aiodns
19
20    loop = asyncio.get_event_loop()
21    resolver = aiodns.DNSResolver(loop=loop)
22    f = resolver.query('google.com','A')
23    result = loop.run_until_complete(f)
24    print(result)
25
26
27The following query types are supported: A, AAAA, CNAME, MX, NAPTR, NS, PTR, SOA, SRV, TXT.
28
29The library supports both *asyncio* and *Trollius*.
30
31If you use Python 3 you may use `yield from` statement::
32
33    @asyncio.coroutine
34    def func():
35        result = yield from resolver.query('google.com','A')
36
37For Trollius you should use another syntax like::
38
39    @trollius.coroutine
40    def func():
41         result = yield trollius.From(resolver.query('google.com','A'))
42
43API
44===
45
46The API is pretty simple, three functions are provided in the ``DNSResolver`` class:
47
48* ``query(host, type)``: Do a DNS resolution of the given type for the given hostname. It returns an
49  instance of ``asyncio.Future``. The actual result of the DNS query is taken directly from pycares.
50  As of version 1.0.0 of aiodns (and pycares, for that matter) results are always namedtuple-like
51  objects with different attributes. Please check `the documentation <http://pycares.readthedocs.org/en/latest/channel.html#pycares.Channel.query>`_
52  for the result fields.
53* ``gethostbyname(host, socket_family)``: Do a DNS resolution for the given
54  hostname and the desired type of address family (i.e. ``socket.AF_INET``).
55  While ``query()`` always performs a request to a DNS server,
56  ``gethostbyname()`` first looks into ``/etc/hosts`` and thus can resolve
57  local hostnames (such as ``localhost``).  Please check `the documentation
58  <http://pycares.readthedocs.io/en/latest/channel.html#pycares.Channel.gethostbyname>`_
59  for the result fields. The actual result of the call is a ``asyncio.Future``.
60* ``cancel()``: Cancel all pending DNS queries. All futures will get ``DNSError`` exception set, with
61  ``ARES_ECANCELLED`` errno.
62
63
64Running the test suite
65======================
66
67To run the test suite: ``python test_aiodns.py``
68
69
70Author
71======
72
73Saúl Ibarra Corretgé <saghul@gmail.com>
74
75
76License
77=======
78
79aiodns uses the MIT license, check LICENSE file.
80
81
82Python versions
83===============
84
85Python >= 3.4 is natively supported. Python 3.3 supported using the `asyncio package <https://pypi.python.org/pypi/asyncio>`_.
86Older Python versions(2.6 - 3.2) are supported using `trollius <https://pypi.python.org/pypi/trollius>`_.
87
88
89Contributing
90============
91
92If you'd like to contribute, fork the project, make a patch and send a pull
93request. Have a look at the surrounding code and please, make yours look
94alike :-)
95
96