Twisted Asynchronous Networking Framework

25.5.0 · active · verified Thu Apr 09

Twisted is a powerful, event-driven networking framework for Python, enabling asynchronous programming with a strong emphasis on protocols and concurrency. It provides abstractions for common network programming tasks, including TCP/UDP, HTTP, DNS, and more. It is actively maintained with frequent releases, typically every 1-3 months. The current stable version is 25.5.0.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a simple echo server using Twisted's core `reactor` and `protocol` abstractions. It listens on port 8000 and sends back any data received.

from twisted.internet import reactor, protocol

class Echo(protocol.Protocol):
    """As soon as any data is received, send it back."""
    def dataReceived(self, data):
        self.transport.write(data)

class EchoFactory(protocol.Factory):
    def buildProtocol(self, addr):
        return Echo()

if __name__ == '__main__':
    # This will run the protocol on port 8000
    reactor.listenTCP(8000, EchoFactory())
    print("Echo server started on port 8000. Press Ctrl+C to stop.")
    reactor.run()

view raw JSON →