pyasynchat

A drop-in backport of Python's removed asynchat module for Python 3.12 and later

Library
PyPI
v1.0.5
3stars
PSF-2.0

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
22/100Needs Attention
Development Activity4
Maintenance20
Community8
Maturity56
Momentum0

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
50/100Fair
Architecture50
Code Quality55
Innovation40
Learning Curve55

pyasynchat restores the asynchat module that Python removed in version 3.12, letting existing async chat-style networking code that relies on import asynchat keep working without refactoring. It packages the exact source from the Python 3.9 standard library — the last version before deprecation warnings were added — as a standalone PyPI installable module.

The library is intentionally minimal: it doesn’t extend or modernize asynchat’s API, it simply preserves it. Projects still depending on the deprecated command/response networking pattern (used historically by protocols like SMTP, NNTP, and FTP clients) can install this package to bridge the gap while they migrate to asyncio, which the Python core team now recommends for new development.

What You Get

  • The exact asynchat source from Python 3.9’s standard library, including the async_chat dispatcher class and find_prefix_at_end helper
  • Zero code changes required — existing import asynchat statements resolve to this package automatically on Python 3.12+
  • The full backported unittest suite replicated from CPython’s own asynchat tests, runnable via python -m unittest
  • PSF-licensed source, matching the licensing of the original standard library module

Common Use Cases

  • Keeping a legacy SMTP, NNTP, or FTP client/server built on asynchat running after upgrading to Python 3.12 or later
  • Buying time to migrate an asynchat-based codebase to asyncio without blocking a Python version upgrade
  • Running third-party libraries or internal tools that still import asynchat on a modern Python interpreter

Under The Hood

Architecture: pyasynchat is a single-module package (asynchat/__init__.py, ~300 lines) exposing one public class, async_chat, an abstract subclass of asyncore.dispatcher (from the companion pyasyncore backport). Consumers subclass async_chat and implement collect_incoming_data() and found_terminator(); the base class drives a handle_read() loop that buffers socket data, scans it for a configurable terminator (a fixed byte string, an integer byte count, or None), and dispatches to those two callbacks as terminators are found. A companion async_chat.push() / producer_fifo mechanism (backed by a collections.deque) handles outbound data queuing. There is no additional abstraction beyond this single dispatcher class — the module’s entire job is reproducing the removed stdlib behavior byte-for-byte.

Tech Stack: Pure Python 3, stdlib-only at runtime aside from its one declared dependency, pyasyncore>=1.0.2 (a sibling backport of the also-removed asyncore module, by the same maintainer). Packaging uses a plain setuptools setup.py with no build backend beyond that — no compiled extensions, no optional extras.

Code Quality: The module carries its original Sam Rushing / CPython copyright header and inline comments largely unchanged from the standard library source, so naming and style follow historic CPython conventions (e.g. ac_in_buffer_size) rather than modern idioms, and there are no type hints. Tests exist and are substantial: tests/test_asynchat.py replicates CPython’s own asynchat test suite (14 test functions covering terminator handling, partial reads, push/close semantics, and error paths) using real sockets and threading via the test.support helpers bundled with CPython itself, run with python -m unittest. Error handling mirrors the original stdlib module — handle_read() catches BlockingIOError and delegates other OSErrors to handle_error().

API Design: Because the entire point of the package is byte-for-byte compatibility with the removed standard-library module, the public API is identical to the original asynchat — there is nothing new to learn for anyone who has used it before, and the official CPython documentation (linked from the README) doubles as this package’s documentation. The tradeoff is that the API itself is dated: two abstract methods must be implemented by hand, terminator state is mutated as an instance attribute rather than passed explicitly, and there is no asyncio-style coroutine interface. The README is explicit that this is a compatibility shim, not a recommended pattern for new code, and points users toward asyncio instead.

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search