{"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":"python","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,"search_vec":"'-3':51 '1':50 '25.5.0':58 'abstract':29 'activ':43 'async':59 'asynchron':2,17 'common':31 'concurr':26 'current':54 'dns':38 'driven':11,63 'emphasi':22 'enabl':16 'event':10,62 'event-driven':9,61 'everi':49 'framework':4,13,64 'frequent':46 'http':37 'includ':35 'maintain':44 'month':52 'network':3,12,32,60 'power':8 'program':18,33 'protocol':24,65 'provid':28 'python':15 'reactor':66 'releas':47 'stabl':55 'strong':21 'task':34 'tcp/udp':36 'twist':1,5 'typic':48 'version':56","created_at":"2026-04-09T04:01:36.428757+00:00","updated_at":"2026-04-16T23:23:11.336631+00:00","problems":[{"fix":"Ensure `reactor.run()` is called only once per application lifecycle. For scheduling tasks after the reactor starts, use `reactor.callWhenRunning(my_function)`.","cause":"The Twisted reactor (responsible for the event loop) was attempted to be started again using `reactor.run()` while it was already active.","error":"RuntimeError: Reactor already running"},{"fix":"Add an `addErrback` callback to your Deferred chain to catch and process exceptions, for example: `d.addErrback(lambda failure: print(f\"Error: {failure.getErrorMessage()}\"))`.","cause":"A `Deferred` object encountered an exception during its callback chain, but no `errback` was attached to handle the failure, causing it to be logged as unhandled.","error":"Unhandled error in Deferred:"},{"fix":"Verify that the target server application is running and listening on the correct host and port, and check network connectivity and firewall rules.","cause":"A client attempted to connect to a server at a specific host and port, but the connection was actively refused because the server was not running, was unreachable, or a firewall blocked the connection.","error":"twisted.internet.error.ConnectionRefusedError: Connection refused"},{"fix":"Import the reactor specifically from the `twisted.internet` module: `from twisted.internet import reactor`.","cause":"The Twisted reactor was attempted to be accessed directly via `twisted.reactor`, but the `reactor` object resides within the `twisted.internet` submodule.","error":"AttributeError: module 'twisted' has no attribute 'reactor'"},{"fix":"Increase the timeout value for the operation if it is expected to take longer, or investigate network latency and performance issues.","cause":"A network operation (e.g., connection attempt or data transfer) exceeded the configured timeout period before it could complete.","error":"twisted.internet.error.TimeoutError: User timeout caused connection failure."}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"26.4.0","cli_name":"twistd","cli_version":"twistd (the Twisted daemon) 26.4.0","type":"library","homepage":"https://twisted.org/","github":"https://github.com/twisted/twisted","docs":"https://docs.twisted.org/","changelog":"https://github.com/twisted/twisted/blob/HEAD/NEWS.rst","pypi":"https://pypi.org/project/twisted/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["http-networking","web-framework"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-08-27","next_check":"2026-07-28","install_tag":null}}