Install & Compatibility
Where this runs
tested against v1.0.5 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.940 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.9MB
glibcpy 3.10–3.940 runs
installs and imports cleanly · install 1.6s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
async_chat
✓ from asynchat import async_chat
✗ from pyasynchat import async_chat
This quickstart demonstrates a simple asynchronous echo server using `pyasynchat` for handling client communication and `pyasyncore` for the main event loop. It mirrors the functionality of a classic `asynchat` example.
import socket
import pyasyncore
from pyasynchat import async_chat, simple_producer # simple_producer is imported but not used for brevity in this example
class EchoHandler(async_chat):
def __init__(self, sock):
super().__init__(sock)
self.set_terminator(b'\n')
self.data = []
def collect_incoming_data(self, data):
self.data.append(data)
def found_terminator(self):
message = b"".join(self.data).strip()
print(f"Received: {message.decode()}")
self.push(message + b'\n') # Echo back with a newline
self.data = []
class EchoServer(pyasyncore.dispatcher):
def __init__(self, host, port):
super().__init__()
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.set_reuse_addr()
self.bind((host, port))
self.listen(5)
print(f"Listening on {host}:{port}")
def handle_accept(self):
pair = self.accept()
if pair is not None:
sock, addr = pair
print(f"Incoming connection from {addr}")
EchoHandler(sock)
if __name__ == "__main__":
# The loop function must be imported from pyasyncore, not pyasynchat.
# Ensure pyasyncore is also installed: pip install pyasyncore
server = EchoServer('localhost', 8080)
try:
pyasyncore.loop()
except KeyboardInterrupt:
print("Server stopped.")
# To test: In another terminal, run: nc localhost 8080
Debug
Known issues
breakingThe original `asynchat` standard library module was removed from Python 3.12 and later versions.fixMigrate applications to use `pyasynchat` (and `pyasyncore`) as external packages.
affects: Python 3.12+
breakingApplications using `asynchat` must update their import statements to use `pyasynchat`.fixChange `import asynchat` to `import pyasynchat` or `from asynchat import ...` to `from pyasynchat import ...`.
affects: Python 3.12+
gotcha`pyasynchat` relies on `pyasyncore` for the underlying asynchronous event loop (`asyncore.loop`). Both packages must be installed for `pyasynchat` to function correctly.fixEnsure `pip install pyasynchat pyasyncore` is run, and update any `asyncore.loop()` calls to `pyasyncore.loop()` if `asyncore` itself was previously imported directly.
affects: All versions of `pyasynchat`
gotchaAs a re-implementation of a removed standard library module, while aiming for high compatibility, subtle behavioral differences might exist compared to the original CPython standard library versions of `asynchat` and `asyncore`.fixThoroughly test existing applications after migration to `pyasynchat` and `pyasyncore` to ensure no unexpected behavior changes.
affects: All versions
Upgrade
Version history
1.0.5latest on PyPI · released Jan 5, 2026
Audit
Dependencies
pyasyncorerequiredpyasynchat is built on pyasyncore and requires it for core asynchronous event loop functionality.