{"id":14631001,"url":"https://github.com/aio-libs/aiodns","last_synced_at":"2026-05-16T04:01:09.520Z","repository":{"id":15425155,"uuid":"18157561","full_name":"aio-libs/aiodns","owner":"aio-libs","description":"Simple DNS resolver for asyncio","archived":false,"fork":false,"pushed_at":"2026-05-07T15:53:49.000Z","size":176,"stargazers_count":592,"open_issues_count":15,"forks_count":73,"subscribers_count":12,"default_branch":"master","last_synced_at":"2026-05-08T00:39:07.522Z","etag":null,"topics":["asyncio","dns","python"],"latest_commit_sha":null,"homepage":"https://pypi.org/p/aiodns","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/aio-libs.png","metadata":{"files":{"readme":"README.rst","changelog":"ChangeLog","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2014-03-26T23:19:57.000Z","updated_at":"2026-05-07T16:03:19.000Z","dependencies_parsed_at":"2024-03-31T12:26:29.894Z","dependency_job_id":"bd10ca20-66e0-4b72-a1ee-7d7b6945ebd8","html_url":"https://github.com/aio-libs/aiodns","commit_stats":{"total_commits":105,"total_committers":26,"mean_commits":4.038461538461538,"dds":0.5904761904761905,"last_synced_commit":"aac8df5e650efd94ad71566a070a0a91b8233840"},"previous_names":["saghul/aiodns"],"tags_count":23,"template":false,"template_full_name":null,"purl":"pkg:github/aio-libs/aiodns","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aio-libs%2Faiodns","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aio-libs%2Faiodns/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aio-libs%2Faiodns/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aio-libs%2Faiodns/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aio-libs","download_url":"https://codeload.github.com/aio-libs/aiodns/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aio-libs%2Faiodns/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32797614,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-08T08:22:46.396Z","status":"ssl_error","status_checked_at":"2026-05-08T08:22:45.650Z","response_time":54,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["asyncio","dns","python"],"created_at":"2024-09-09T13:02:01.652Z","updated_at":"2026-05-16T04:01:09.513Z","avatar_url":"https://github.com/aio-libs.png","language":"Python","funding_links":[],"categories":["Python","Others"],"sub_categories":[],"readme":"===============================\nSimple DNS resolver for asyncio\n===============================\n\n.. image:: https://badge.fury.io/py/aiodns.png\n    :target: https://pypi.org/project/aiodns/\n\n.. image:: https://github.com/saghul/aiodns/workflows/CI/badge.svg\n    :target: https://github.com/saghul/aiodns/actions\n\naiodns provides a simple way for doing asynchronous DNS resolutions using `pycares \u003chttps://github.com/saghul/pycares\u003e`_.\n\n\nExample\n=======\n\n.. code:: python\n\n    import asyncio\n    import aiodns\n\n    async def main():\n        resolver = aiodns.DNSResolver()\n        result = await resolver.query_dns('google.com', 'A')\n        for record in result.answer:\n            print(record.data.addr)\n\n    asyncio.run(main())\n\n\nThe following query types are supported: A, AAAA, ANY, CAA, CNAME, MX, NAPTR, NS, PTR, SOA, SRV, TXT.\n\n\nAPI\n===\n\nThe API is pretty simple, the following functions are provided in the ``DNSResolver`` class:\n\n* ``query_dns(host, type)``: Do a DNS resolution of the given type for the given hostname. It returns an\n  instance of ``asyncio.Future``. The result is a ``pycares.DNSResult`` object with ``answer``,\n  ``authority``, and ``additional`` attributes containing lists of ``pycares.DNSRecord`` objects.\n  Each record has ``type``, ``ttl``, and ``data`` attributes. Check the `pycares documentation\n  \u003chttps://pycares.readthedocs.io/\u003e`_ for details on the data attributes for each record type.\n* ``query(host, type)``: **Deprecated** - use ``query_dns()`` instead. This method returns results\n  in a legacy format compatible with aiodns 3.x for backward compatibility.\n* ``gethostbyname(host, socket_family)``: **Deprecated** - use ``getaddrinfo()`` instead.\n  Do a DNS resolution for the given hostname and the desired type of address family\n  (i.e. ``socket.AF_INET``). The actual result of the call is a ``asyncio.Future``.\n* ``gethostbyaddr(name)``: Make a reverse lookup for an address.\n* ``getaddrinfo(host, family, port, proto, type, flags)``: Resolve a host and port into a list of\n  address info entries.\n* ``getnameinfo(sockaddr, flags)``: Resolve a socket address to a host and port.\n* ``cancel()``: Cancel all pending DNS queries. All futures will get ``DNSError`` exception set, with\n  ``ARES_ECANCELLED`` errno.\n* ``close()``: Close the resolver. This releases all resources and cancels any pending queries. It must be called\n  when the resolver is no longer needed (e.g., application shutdown). The resolver should only be closed from the\n  event loop that created the resolver.\n\n\nMigrating from aiodns 3.x\n=========================\n\naiodns 4.x introduces a new ``query_dns()`` method that returns native pycares 5.x result types.\nSee the `pycares documentation \u003chttps://pycares.readthedocs.io/latest/channel.html#pycares.Channel.query\u003e`_\nfor details on the result types. The old ``query()`` method is deprecated but continues to work\nfor backward compatibility.\n\n.. code:: python\n\n    # Old API (deprecated)\n    result = await resolver.query('example.com', 'MX')\n    for record in result:\n        print(record.host, record.priority)\n\n    # New API (recommended)\n    result = await resolver.query_dns('example.com', 'MX')\n    for record in result.answer:\n        print(record.data.exchange, record.data.priority)\n\n\nFuture migration to aiodns 5.x\n------------------------------\n\nThe temporary ``query_dns()`` naming allows gradual migration without breaking changes:\n\n+-----------+---------------------------------------+--------------------------------------------+\n| Version   | ``query()``                           | ``query_dns()``                            |\n+===========+=======================================+============================================+\n| **4.x**   | Deprecated, returns compat types      | New API, returns pycares 5.x types         |\n+-----------+---------------------------------------+--------------------------------------------+\n| **5.x**   | New API, returns pycares 5.x types    | Alias to ``query()`` for back compat       |\n+-----------+---------------------------------------+--------------------------------------------+\n\nIn aiodns 5.x, ``query()`` will become the primary API returning native pycares 5.x types,\nand ``query_dns()`` will remain as an alias for backward compatibility. This allows downstream\nprojects to migrate at their own pace.\n\n\nAsync Context Manager Support\n=============================\n\nWhile not recommended for typical use cases, ``DNSResolver`` can be used as an async context manager\nfor scenarios where automatic cleanup is desired:\n\n.. code:: python\n\n    async with aiodns.DNSResolver() as resolver:\n        result = await resolver.query_dns('example.com', 'A')\n        # resolver.close() is called automatically when exiting the context\n\n**Important**: This pattern is discouraged for most applications because ``DNSResolver`` instances\nare designed to be long-lived and reused for many queries. Creating and destroying resolvers\nfrequently adds unnecessary overhead. Use the context manager pattern only when you specifically\nneed automatic cleanup for short-lived resolver instances, such as in tests or one-off scripts.\n\n\nNote for Windows users\n======================\n\nThis library requires the use of an ``asyncio.SelectorEventLoop`` or ``winloop`` on Windows\n**only** when using a custom build of ``pycares`` that links against a system-\nprovided ``c-ares`` library **without** thread-safety support. This is because\nnon-thread-safe builds of ``c-ares`` are incompatible with the default\n``ProactorEventLoop`` on Windows.\n\nIf you're using the official prebuilt ``pycares`` wheels on PyPI (version 4.7.0 or\nlater), which include a thread-safe version of ``c-ares``, this limitation does\n**not** apply and can be safely ignored.\n\nThe default event loop can be changed as follows (do this very early in your application):\n\n.. code:: python\n\n    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())\n\nThis may have other implications for the rest of your codebase, so make sure to test thoroughly.\n\n\nRunning the test suite\n======================\n\nTo run the test suite: ``python -m pytest tests/``\n\n\nReleasing (maintainers only)\n============================\n\nReleases are cut from ``master`` and published to PyPI automatically by the\n``Release Wheels`` workflow when a GitHub Release is created.\n\n1. **Prepare the release PR.** Bump ``__version__`` in ``aiodns/__init__.py``\n   and prepend a section to ``ChangeLog`` describing the user-facing changes\n   since the previous tag, in the same RST style as the existing entries\n   (``X.Y.Z`` header underlined with ``=``). Open the PR with the title\n   ``Release X.Y.Z`` and merge it once CI is green.\n\n2. **Tag and publish the release.** From a clean checkout of ``master`` that\n   includes the merged release PR, generate the release notes from\n   ``ChangeLog`` and create the GitHub release in one shot::\n\n       python scripts/release-notes.py --target X.Y.Z \\\n           | gh release create vX.Y.Z --repo aio-libs/aiodns \\\n                 --title vX.Y.Z --notes-file -\n\n   The helper script reads ``__version__`` and the topmost ``ChangeLog``\n   section and aborts non-zero if they disagree, or if ``--target`` does\n   not match the current state on disk, so you can't accidentally publish\n   notes for a version the release PR hasn't actually landed yet.\n\n3. **Watch the wheel build.** Publishing the GitHub release fires\n   ``release-wheels.yml``, which builds wheels + sdist and pushes them to\n   `PyPI \u003chttps://pypi.org/project/aiodns/\u003e`_ via trusted publishing\n   (no token required). Confirm the run succeeds::\n\n       gh run list --repo aio-libs/aiodns --workflow release-wheels.yml --limit 1\n\n\nAuthor\n======\n\nSaúl Ibarra Corretgé \u003cs@saghul.net\u003e\n\n\nLicense\n=======\n\naiodns uses the MIT license, check LICENSE file.\n\n\nContributing\n============\n\nIf you'd like to contribute, fork the project, make a patch and send a pull\nrequest. Have a look at the surrounding code and please, make yours look\nalike :-)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faio-libs%2Faiodns","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faio-libs%2Faiodns","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faio-libs%2Faiodns/lists"}