Twisted is a Python event-based framework for building internet applications. It ships protocol modules for HTTP, mail, SSH, DNS, IRC, XMPP, and more.
Overview
Twisted is an event-driven networking engine for Python aimed at internet protocols and custom network programs. It lets developers implement servers and clients around a single reactor model instead of blocking threads for each connection.
Bundled subprojects cover common protocols: HTTP clients and servers with HTML templating and a WSGI server, SSH and Telnet via conch, IRC and XMPP via words, IMAP/POP/SMTP mail, DNS via names, GPS tooling, and an integrated trial test runner. Examples on the project site show TCP echo servers, web counters, pub/sub lines, IMAP clients, and SSH command clients.
The reactor abstraction supports major system event loops including select, poll, epoll on Linux, kqueue on FreeBSD and macOS, IOCP on Windows, and several GUI loops. Third-party reactors can plug in for additional environments. Installation is available through pip, with documentation and API references published separately.
Twisted targets authors who need fine-grained control over protocol behavior in Python, from small network utilities to long-lived services, and supports CPython 3.7+ and PyPy3.
Key features
- HTTP client and server modules
- SSHv2 and Telnet support
- IRC, XMPP, and IM protocols
- IMAP, POP3, and SMTP mail
- DNS client and server tools
- Pluggable reactor event loops
- Integrated trial testing framework
- WSGI-capable web server
Use cases
- Custom TCP and UDP network services
- Mail and messaging protocol servers
- SSH automation clients
- Embedded HTTP microservices in Python
- Protocol prototyping and learning