{"id":1752,"library":"twisted","title":"Twisted Asynchronous Networking Framework","description":"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.","status":"active","version":"25.5.0","language":"en","source_language":"en","source_url":"https://github.com/twisted/twisted","tags":["async","networking","event-driven","framework","protocols","reactor"],"install":[{"cmd":"pip install twisted","lang":"bash","label":"Install latest stable version"}],"dependencies":[{"reason":"Core dependency for interface definition and implementation.","package":"zope.interface","optional":false},{"reason":"Required for TLS/SSL support, especially for clients and servers.","package":"pyopenssl","optional":true},{"reason":"Used for verifying server certificates in TLS connections.","package":"service_identity","optional":true},{"reason":"Underpins TLS/SSL and other cryptographic features.","package":"cryptography","optional":true}],"imports":[{"note":"The core event loop object.","symbol":"reactor","correct":"from twisted.internet import reactor"},{"note":"Base classes for implementing network protocols.","symbol":"protocol","correct":"from twisted.internet import protocol"},{"note":"Module for Deferred objects and inlineCallbacks.","symbol":"defer","correct":"from twisted.internet import defer"},{"note":"Common imports for building web applications.","symbol":"server","correct":"from twisted.web import server, resource"}],"quickstart":{"code":"from twisted.internet import reactor, protocol\n\nclass Echo(protocol.Protocol):\n    \"\"\"As soon as any data is received, send it back.\"\"\"\n    def dataReceived(self, data):\n        self.transport.write(data)\n\nclass EchoFactory(protocol.Factory):\n    def buildProtocol(self, addr):\n        return Echo()\n\nif __name__ == '__main__':\n    # This will run the protocol on port 8000\n    reactor.listenTCP(8000, EchoFactory())\n    print(\"Echo server started on port 8000. Press Ctrl+C to stop.\")\n    reactor.run()","lang":"python","description":"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."},"warnings":[{"fix":"Migrate away from these deprecated methods. Twisted's `trial` testing framework encourages standard async/await or direct Deferred usage for setup/teardown.","message":"The methods `deferSetUp`, `deferTestMethod`, `deferTearDown`, and `deferRunCleanups` on `twisted.trial.unittest.TestCase` have been removed.","severity":"breaking","affected_versions":"25.5.0 and later"},{"fix":"Always use Twisted's asynchronous primitives (e.g., `reactor.callLater`, `defer.Deferred`, `inlineCallbacks`, `twisted.internet.threads.deferToThread`) for operations that might block. Offload CPU-bound tasks to separate threads or processes.","message":"Any blocking call (e.g., `time.sleep()`, synchronous I/O, long-running computations) will halt the entire Twisted reactor and block all other active connections and operations.","severity":"gotcha","affected_versions":"All versions"},{"fix":"If you relied on the exact creation traceback for debugging, be aware this information is no longer available. Focus on the traceback within the `Failure` object itself, which points to where the error occurred, rather than where the `Failure` object was instantiated.","message":"The `twisted.python.failure.Failure` object, which encapsulates tracebacks for error handling, no longer records the exact point of its creation for performance reasons.","severity":"gotcha","affected_versions":"24.10.0 and later"},{"fix":"Always attach an errback to the end of a Deferred chain to catch and log unhandled errors, or ensure that all possible error paths are explicitly handled. Use `inlineCallbacks` or Python's `async/await` syntax (when yielding coroutines, supported from 24.7.0) to simplify Deferred management.","message":"Understanding and correctly chaining `defer.Deferred` objects, especially handling errors (errbacks), can be complex. Unhandled errors in a Deferred chain can silently disappear or lead to unexpected behavior.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}