{"library":"pycares","code":"import pycares\nimport socket\n\ndef callback(result, error):\n    if error:\n        print(f\"Error: {error}\")\n        return\n    if result:\n        for record in result.answer:\n            if record.type == pycares.QUERY_TYPE_A:\n                print(f\"A record for {record.name}: {record.data.addr}\")\n            elif record.type == pycares.QUERY_TYPE_AAAA:\n                print(f\"AAAA record for {record.name}: {record.data.addr}\")\n            elif record.type == pycares.QUERY_TYPE_MX:\n                print(f\"MX record for {record.name}: priority={record.data.priority}, exchange={record.data.exchange}\")\n            # Add other record types as needed\n    else:\n        print(\"No records found.\")\n\n\n# Using a simple select-based event loop\nchannel = pycares.Channel(timeout=5.0)\n\n# Query for A records\nchannel.query(\"google.com\", pycares.QUERY_TYPE_A, callback=callback)\n\n# Query for MX records\nchannel.query(\"example.com\", pycares.QUERY_TYPE_MX, callback=callback)\n\n# Basic event loop processing\nwhile True:\n    read_fds, write_fds = channel.getsockname()\n    if not read_fds and not write_fds:\n        break\n    \n    # In a real application, use an actual event loop (e.g., asyncio, Tornado, Gevent)\n    # For this simple example, we block briefly\n    try:\n        rlist, wlist, xlist = socket.select(read_fds, write_fds, [], 1.0)\n    except socket.error as e:\n        print(f\"Socket error in select: {e}\")\n        break\n\n    channel.process_fd(rlist, wlist)\n","lang":"python","description":"This quickstart demonstrates how to perform asynchronous DNS queries for A and MX records using `pycares`. It sets up a `Channel` and makes two queries with a shared callback function. A basic `select`-based loop is used to process file descriptors and handle the asynchronous responses. In a production environment, `pycares` is typically integrated with a more robust event loop like `asyncio` (via `aiodns`), `Tornado`, or `Gevent`.","tag":null,"tag_description":null,"last_tested":"2026-04-24","results":[{"runtime":"python:3.10-alpine","exit_code":1},{"runtime":"python:3.10-slim","exit_code":1},{"runtime":"python:3.11-alpine","exit_code":1},{"runtime":"python:3.11-slim","exit_code":1},{"runtime":"python:3.12-alpine","exit_code":1},{"runtime":"python:3.12-slim","exit_code":1},{"runtime":"python:3.13-alpine","exit_code":1},{"runtime":"python:3.13-slim","exit_code":1},{"runtime":"python:3.9-alpine","exit_code":1},{"runtime":"python:3.9-slim","exit_code":1}]}