{"id":5796,"library":"pyasyncore","title":"pyasyncore library","description":"pyasyncore is a compatibility library that re-introduces the `asyncore` module, which was removed from the Python standard library in version 3.12. It allows existing codebases that rely on `asyncore` to continue functioning on Python 3.12 and later. The current version is 1.0.5, with releases typically tied to Python version compatibility or critical bug fixes.","status":"active","version":"1.0.5","language":"en","source_language":"en","source_url":"https://github.com/simonrob/pyasyncore","tags":["networking","async","compatibility","backport","legacy"],"install":[{"cmd":"pip install pyasyncore","lang":"bash","label":"Install pyasyncore"}],"dependencies":[],"imports":[{"note":"The library provides the top-level 'asyncore' module, mimicking the standard library behavior prior to Python 3.12.","symbol":"asyncore","correct":"import asyncore"},{"note":"While 'pyasyncore' primarily backports 'asyncore', the related 'pyasynchat' library (from the same author) backports 'asynchat'.","symbol":"asynchat","correct":"import asynchat"}],"quickstart":{"code":"import asyncore\nimport socket\n\nclass EchoHandler(asyncore.dispatcher_with_send):\n    def handle_read(self):\n        data = self.recv(8192)\n        if data:\n            self.send(data)\n\nclass EchoServer(asyncore.dispatcher):\n    def __init__(self, host, port):\n        asyncore.dispatcher.__init__(self)\n        self.create_socket(socket.AF_INET, socket.SOCK_STREAM)\n        self.set_reuse_addr()\n        self.bind((host, port))\n        self.listen(5)\n        print(f\"Echo server listening on {host}:{port}\")\n\n    def handle_accept(self):\n        pair = self.accept()\n        if pair is not None:\n            sock, addr = pair\n            print(f\"Incoming connection from {repr(addr)}\")\n            handler = EchoHandler(sock)\n\nif __name__ == \"__main__\":\n    # Note: asyncore is blocking. For a simple example, it runs forever.\n    # In a real application, you might run it in a separate thread \n    # or integrate it with other event loops (though this defeats its purpose).\n    try:\n        server = EchoServer('127.0.0.1', 8080)\n        asyncore.loop()\n    except KeyboardInterrupt:\n        print(\"\\nServer stopped.\")\n","lang":"python","description":"This quickstart demonstrates a basic `asyncore` echo server. It creates a server that listens on `127.0.0.1:8080` and echoes back any data received from connected clients. Run this script, then connect with `nc 127.0.0.1 8080` in another terminal to test. This example is identical to how `asyncore` would have been used in Python versions prior to 3.12."},"warnings":[{"fix":"Install `pyasyncore` to restore the `asyncore` module for compatibility: `pip install pyasyncore`.","message":"The `asyncore` module was removed from the Python standard library starting with Python 3.12. Code relying on `import asyncore` will raise an `ImportError` on Python 3.12 and later.","severity":"breaking","affected_versions":"Python 3.12+"},{"fix":"For new projects or significant refactoring, consider migrating to `asyncio` to leverage modern async/await syntax and better ecosystem support.","message":"`asyncore` is a legacy module. While `pyasyncore` provides compatibility for older code, for new asynchronous application development, Python's `asyncio` module is the modern and recommended approach.","severity":"gotcha","affected_versions":"All versions using `pyasyncore`"},{"fix":"Only install and use `pyasyncore` on Python 3.12 or newer, where the standard library `asyncore` is absent.","message":"`pyasyncore` is specifically intended to provide `asyncore` for Python 3.12 and newer. Installing it on older Python versions (where `asyncore` is still part of the standard library) may lead to shadowing the built-in module, potentially causing subtle behavioral differences or confusion.","severity":"gotcha","affected_versions":"Python versions < 3.12"}],"env_vars":null,"last_verified":"2026-04-14T00:00:00.000Z","next_check":"2026-07-13T00:00:00.000Z"}