aiodns is a Python library that provides a simple way to perform asynchronous DNS resolutions using the `asyncio` framework and `pycares` as its backend. The current version is 4.0.0, and it generally follows an active release cadence with several updates throughout the year to improve performance, add features, and maintain compatibility with newer Python and `pycares` versions.
pip install aiodnsVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to perform an asynchronous 'A' record DNS lookup using the `DNSResolver` class and its recommended `query_dns` method. It includes basic error handling and shows the crucial step of closing the resolver to release resources.
Ensure `pycares` is updated to version 5.0.0 or higher by running `pip install 'pycares>=5.0.0'`.
Migrate your code to use `await resolver.query_dns(host, type)` instead of `await resolver.query(host, type)` to benefit from native `pycares` result types and future compatibility. Review `pycares` documentation for details on `DNSResult` structure.
Replace calls to `gethostbyname()` with `getaddrinfo()`. This aligns with modern socket API practices and offers better IPv6 support and flexibility.
For most applications, create a single `DNSResolver` instance and reuse it. Ensure you `await resolver.close()` explicitly when the application is shutting down or the resolver is definitively no longer needed. Avoid creating and destroying `DNSResolver` objects in a tight loop.
Most users can safely ignore this warning when using official `pycares` wheels. If you encounter issues on Windows or are using a custom `pycares` build, consider explicitly setting the event loop to `SelectorEventLoop` or using `winloop`.
Install the 'aiodns' module using pip: 'pip install aiodns'.
Ensure you are using the correct version of 'aiodns' and import 'DNSResolver' correctly: 'from aiodns import DNSResolver'.
Update 'aiodns' to the latest version using pip: 'pip install --upgrade aiodns'.
Add 'if sys.platform == 'win32': asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())' at the very beginning of your application code before any asyncio operations.
Upgrade 'pycares' to a version compatible with your 'aiodns' installation, usually by running 'pip install --upgrade pycares'.