# aiohttp-asyncmdnsresolver

## Introduction

This module provides an `aiohttp` resolver that supports mDNS, using the `zeroconf` library to resolve `.local` host names. Any host name that is not in the `.local` domain is delegated to `aiohttp`’s standard `AsyncResolver`, so either resolver is a drop-in replacement for it.

Two resolver classes are provided:

`AsyncMDNSResolver`

  Resolves `.local` names with mDNS only, and every other name with regular DNS.

`AsyncDualMDNSResolver`

  Resolves `.local` names with both mDNS and regular DNS concurrently and returns the first successful result. Use this when `.local` names may also be served by a unicast DNS server.

## Installation

    $ pip install aiohttp-asyncmdnsresolver

## Usage

Pass a resolver to an `aiohttp.TCPConnector`. `aiohttp` does not take ownership of a resolver supplied this way, so close it yourself when you are done with it:

    import asyncio

    import aiohttp
    from aiohttp_asyncmdnsresolver.api import AsyncMDNSResolver

    async def main() -> None:
        resolver = AsyncMDNSResolver()
        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())

Swap `AsyncMDNSResolver` for `AsyncDualMDNSResolver` to resolve `.local` names with both mDNS and unicast DNS at once.

## API documentation

Open Reference for reading full list of available methods.

## Source code

The project is hosted on GitHub

Please file an issue on the bug tracker 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.

Contents:

- Reference
  - `AsyncMDNSResolver`
  - `AsyncDualMDNSResolver`

What's new

- Changelog
  - v0.2.0
    - Bug fixes
    - Features
    - Removals and backward incompatible breaking changes
    - Improved documentation
    - Packaging updates and notes for downstreams
    - Contributor-facing changes
  - v0.1.1
    - Miscellaneous internal changes
  - v0.1.0
    - Features
  - v0.0.3
    - Bug fixes
  - v0.0.2
    - Miscellaneous internal changes
  - v0.0.1

Contributing

- Contributing docs
  - Adding change notes with your PRs
  - Alright! So how to add a news fragment?
  - Examples for adding changelog entries to your Pull Requests

Maintenance

- Release Guide
  - Pre-release activities
  - The release stage

# Indices and tables

- Index

- Module Index

- Search Page