|Version 16 (modified by itamar, 4 years ago) (diff)|
What is Twisted?
Twisted is an event-driven networking engine written in Python and licensed under the open source MIT license.
Twisted makes it easy to implement custom network applications. Here's a TCP server that echoes back everything that's written to it:
from twisted.internet import protocol, reactor class Echo(protocol.Protocol): def dataReceived(self, data): self.transport.write(data) class EchoFactory(protocol.Factory): def buildProtocol(self, addr): return Echo() reactor.listenTCP(1234, EchoFactory()) reactor.run()
Twisted includes an event-driven web server. Here's a sample web application; notice how the resource object persists in memory, rather than being recreated on each request:
from twisted.web import server, resource from twisted.internet import reactor class HelloResource(resource.Resource): isLeaf = True numberRequests = 0 def render_GET(self, request): self.numberRequests += 1 request.setHeader("content-type", "text/plain") return "I am request #" + str(self.numberRequests) + "\n" reactor.listenTCP(8080, server.Site(HelloResource())) reactor.run()
- Get in touch with the Twisted community through email, Stack Overflow or IRC;
- Learn about the Twisted development process and how to contribute;
- Read about software using Twisted and their success stories;
- Find out what Twisted Matrix Laboratories is;
- Learn about the individuals and organisations that aid Twisted with donations of hardware, software, hosting and other things;
- Help improve Twisted on Windows!