aiohttp-asyncmdnsresolver
=========================



Introduction
------------

This module provides an ``aiohttp`` resolver that supports mDNS, which uses the ``zeroconf`` library
to resolve mDNS queries.

For full documentation please read https://aiohttp-asyncmdnsresolver.readthedocs.io.

Installation
------------

.. code-block:: console

   $ pip install aiohttp-asyncmdnsresolver


Quick start
-----------

.. code-block:: python

   import asyncio
   import aiohttp
   from aiohttp_asyncmdnsresolver.api import AsyncMDNSResolver

   async def main():
       resolver = AsyncMDNSResolver()
       # aiohttp does not own a resolver passed to TCPConnector, so close it here.
       try:
           connector = aiohttp.TCPConnector(resolver=resolver)
           async with aiohttp.ClientSession(connector=connector) as session:
               async with session.get('http://example.com') as response:
                   print(response.status)
               async with session.get('http://xxx.local.') as response:
                   print(response.status)
       finally:
           await resolver.close()

   asyncio.run(main())


Resolving with both mDNS and DNS
--------------------------------

``AsyncDualMDNSResolver`` is a variant that resolves ``.local`` names over mDNS
**and** regular DNS concurrently, returning the first successful result. Use it
when a ``.local`` name may be served by a unicast DNS server as well as mDNS.

.. code-block:: python

   import asyncio
   import aiohttp
   from aiohttp_asyncmdnsresolver.api import AsyncDualMDNSResolver

   async def main():
       resolver = AsyncDualMDNSResolver()
       # aiohttp does not own a resolver passed to TCPConnector, so close it here.
       try:
           connector = aiohttp.TCPConnector(resolver=resolver)
           async with aiohttp.ClientSession(connector=connector) as session:
               async with session.get('http://printer.local.') as response:
                   print(response.status)
       finally:
           await resolver.close()

   asyncio.run(main())


API documentation
-----------------

The documentation is located at https://aiohttp-asyncmdnsresolver.readthedocs.io.

Source code
-----------

The project is hosted on GitHub_

Please file an issue on the `bug tracker
<https://github.com/aio-libs/aiohttp-asyncmdnsresolver/issues>`_ if you have found a bug
or have some suggestion in order to improve the library.


Authors and License
-------------------

It's *Apache 2* licensed and freely available.


.. _GitHub: https://github.com/aio-libs/aiohttp-asyncmdnsresolver
