Skip to main content

An async resolver for aiohttp that supports MDNS

Project description

https://github.com/aio-libs/aiohttp-asyncmdnsresolver/actions/workflows/ci-cd.yml/badge.svg https://codecov.io/gh/aio-libs/aiohttp-asyncmdnsresolver/branch/main/graph/badge.svg https://badge.fury.io/py/aiohttp-asyncmdnsresolver.svg https://readthedocs.org/projects/aiohttp-asyncmdnsresolver/badge/?version=latest https://img.shields.io/pypi/pyversions/aiohttp-asyncmdnsresolver.svg Matrix Room — #aio-libs:matrix.org Matrix Space — #aio-libs-space:matrix.org

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiohttp_asyncmdnsresolver-0.2.0.tar.gz (37.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiohttp_asyncmdnsresolver-0.2.0-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

Details for the file aiohttp_asyncmdnsresolver-0.2.0.tar.gz.

File metadata

File hashes

Hashes for aiohttp_asyncmdnsresolver-0.2.0.tar.gz
Algorithm Hash digest
SHA256 aab2cef7ef8ae45b94abf1fc92aa9f4d70cbef7ac0a3d495a86fb96fce357262
MD5 cf1b548f2ce20e7767a73c19741b6fc8
BLAKE2b-256 c1861b94f5669df188f5267e26d48c4cc734b704310e53d695af5f39ee1af67d

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiohttp_asyncmdnsresolver-0.2.0.tar.gz:

Publisher: ci-cd.yml on aio-libs/aiohttp-asyncmdnsresolver

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file aiohttp_asyncmdnsresolver-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for aiohttp_asyncmdnsresolver-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1e6dc01719dc563346ae051122fa7dc3a757317e3e6bf4ef8b23cfd034089c22
MD5 97025715b10826e8033c57183551b95a
BLAKE2b-256 1ed5c08b4e242d50d2aded314a16105ee708946fa3dfd37b837b1ca625d26397

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiohttp_asyncmdnsresolver-0.2.0-py3-none-any.whl:

Publisher: ci-cd.yml on aio-libs/aiohttp-asyncmdnsresolver

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page