/
Depends on
- aiodns (python3-aiodns)
- dh-doc-privacy (dh-doc-privacy)
- dh-python (dh-sequence-python3, pybuild-plugin-pyproject)
- myst-parser (python3-myst-parser)
- pytest (python3-pytest)
- python-pytest-asyncio (python3-pytest-asyncio)
- python-pytest-cov (python3-pytest-cov)
- python3-defaults (python3-all)
- setuptools (python3-setuptools)
- sphinx (dh-sequence-sphinxdoc, python3-sphinx)
- sphinxcontrib-towncrier (python3-sphinxcontrib-towncrier)
- debhelper-compat, python3-aiohttp, python3-zeroconf
README (full)
aiohttp-asyncmdnsresolver
:target: https://github.com/aio-libs/aiohttp-asyncmdnsresolver/actions?query=workflow%3ACI :align: right
:target: https://codecov.io/gh/aio-libs/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
$ pip install aiohttp-asyncmdnsresolver
Quick start
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.
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 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.
| dir | .github/ |
| dir | CHANGES/ |
| dir | debian/ |
| dir | docs/ |
| dir | examples/ |
| dir | requirements/ |
| dir | src/ |
| dir | tests/ |
| file | .codecov.yml |
| file | .coveragerc |
| file | .gitignore |
| file | .mypy.ini |
| file | .pre-commit-config.yaml |
| file | .readthedocs.yaml |
| file | .yamllint |
| file | CHANGES.rst |
| file | LICENSE |
| file | MANIFEST.in |
| file | Makefile |
| file | README.rst |
| file | pyproject.toml |
| file | pytest.ini |
| file | towncrier.toml |