Twisted (software)#Deferreds
{{Short description|Event-driven network programming framework}}
{{Infobox software
| name = Twisted
| logo = Twisted Logo (software).svg
| logo size = 150px
| screenshot =
| caption =
| collapsible =
| author = Glyph Lefkowitz
| developer = Community
| released = {{Start date and age|2002|10|22}}{{Cite mailing list|last=Shtull-Trauring|first=Itamar|title=Twisted 1.0|date=2002-10-22|access-date=2008-08-14|mailing-list=twisted-python|url=http://twistedmatrix.com/pipermail/twisted-python/2002-October/002049.html}}
| latest release version = {{wikidata|property|edit|reference|P348}}
| latest release date = {{start date and age|{{wikidata|qualifier|P348|P577}}}}
| latest preview version =
| latest preview date =
| programming language = Python
| operating system =
| platform =
| size =
| language =
| genre = Event-driven networking
| license = MIT License
}}
Twisted is an event-driven network programming framework written in Python and licensed under the MIT License.
Twisted projects variously support TCP, UDP, SSL/TLS, IP multicast, Unix domain sockets, many protocols (including HTTP, XMPP, NNTP, IMAP, SSH, IRC, FTP, and others), and much more. Twisted is based on the event-driven programming paradigm, which means that users of Twisted write short callbacks which are called by the framework.
Core ideas
=Separation of protocols and transports=
Twisted is designed for complete separation between logical protocols (usually relying on stream-based connection semantics, such as HTTP or POP3) and transport layers supporting such stream-based semantics (such as files, sockets or SSL libraries). Connection between a logical protocol and a transport layer happens at the last possible moment — just before information is passed into the logical protocol instance. The logical protocol is informed of the transport layer instance, and can use it to send messages back and to check for the peer's identity. Note that it is still possible, in protocol code, to deeply query the transport layer on transport issues (such as checking a client-side SSL certificate). Naturally, such protocol code will fail (raise an exception) if the transport layer does not support such semantics.
=Deferreds=
Central to the Twisted application model is the concept of a deferred (elsewhere called a future). A deferred is an instance of a class designed to receive and process a result which has not been computed yet, for example because it is based on data from a remote peer. Deferreds can be passed around, just like regular objects, but cannot be asked for their value. Each deferred supports a callback chain. When the deferred gets the value, it is passed to the functions on the callback chain, with the result of each callback becoming the input for the next. Deferreds make it possible to operate on the result of a function call before its value has become available.
For example, if a deferred returns a string from a remote peer containing an IP address in quad format, a callback can be attached to translate it into a 32-bit number. Any user of the deferred can now treat it as a deferred returning a 32-bit number. This, and the related ability to define "errbacks" (callbacks which are called as error handlers), allows code to specify in advance what to do when an asynchronous event occurs, without stopping to wait for the event. In non-event-driven systems, for example using threads, the operating system incurs premature and additional overhead organizing threads each time a blocking call is made.
=Thread support=
Twisted supports an abstraction over raw threads — using a thread as a deferred source. Thus, a deferred is returned immediately, which will receive a value when the thread finishes. Callbacks can be attached which will run in the main thread, thus alleviating the need for complex locking solutions. A prime example of such usage, which comes from Twisted's support libraries, is using this model to call into databases. The database call itself happens on a foreign thread, but the analysis of the result happens in the main thread.
=Foreign loop support=
Twisted can integrate with foreign event loops, such as those of GTK+, Qt and Cocoa (through PyObjC). This allows using Twisted as the network layer in graphical user interface (GUI) programs, using all of its libraries without adding a thread-per-socket overhead, as using Python's native library would. A full-fledged web server can be integrated in-process with a GUI program using this model, for example.
Applications using Twisted
{{More citations needed section|date=March 2017}}
- The BuildBot continuous-integration system relies on Twisted for client/server communication.{{cite web|url=https://djmitche.github.com/buildbot/docs/0.7.10/#Requirements|title=BuildBot Manual|website=github.com|access-date=2017-10-28|archive-url=https://web.archive.org/web/20120729232916/http://djmitche.github.com/buildbot/docs/0.7.10/#Requirements|archive-date=2012-07-29|url-status=dead}}
- ITA Software has developed an airline-reservation system for Air Canada that uses Twisted extensively.{{cite web|url=http://www.eweek.com/c/a/Application-Development/Python-Slithers-into-Systems/1/|title=Python Slithers into Systems|website=eweek.com}}
- SageMath, an open-source alternative to Mathematica, Maple, Magma, MATLAB, has a web-based interface, SageMath notebook,SageMath#Features that runs on a Twisted server.[https://web.archive.org/web/20220516061211/http://sage.math.washington.edu/home/wdj/expository/gap2007/sage-9-2007.pdf Sage a Basic Overview]
- Twisted was used in the Omegle one-on-one chat service{{cite web|url=http://omegler.blogspot.com/|title=mistah deejay|website=omegler.blogspot.com}} until it was replaced with gevent for performance reasons.{{cite web|url=http://groups.google.com/group/gevent/msg/d15a840088291f61|title=Google Groups|website=groups.google.com}}
- The Apple Calendar Server uses Twisted,{{cite web|url=http://www.calendarserver.org/|title=Calendar and Contacts Server|website=www.calendarserver.org}} as do some internal projects of NASA.
- Conch, an implementation of the Secure Shell (SSH) protocol
- The original version of social networking and microblogging site Jaiku used Twisted.{{Citation needed|date=March 2017}}
- Fluidinfo, an online cloud data-store, uses Twisted extensively for internal RPC (partly in combination with Thrift and AMQP), for its internal services, and for external APIs.
- The file-hosting service Ubuntu One used Twisted.
- Tor2web, an HTTP proxy for Tor Hidden Services (HS), uses Twisted.
- GlobaLeaks, an open-source whistleblowing framework, uses Twisted.
- Cloudkick, a cloud-server management web-application, used Twisted. It now has been rewritten using Node.js.
- Twilio, a cloud telephony provider, uses Twisted.
- Twitch, a video game broadcasting and chat community, uses Twisted.{{cite web|url=http://www.twitch.tv/jobs|title=Twitch - Jobs|website=Twitch}}
- Velocity Weather, a meteorological data processing and integration API is built on Twisted.{{cite web|url=http://www.velocityweather.com/|title=Velocity Weather -|website=www.velocityweather.com}}
- qwebirc, a web-based IRC client, uses Twisted.
- Zenoss Core, a network management platform, uses Twisted for many internal and collection daemons.
- Scrapy, a web crawler based on Twisted.
- Listen to Wikipedia, a Wikipedia audio-visualizer, uses Twisted to broadcast real-time edit events to browsers.{{Citation|title=A WebSocket-oriented monitor for Wikipedia (also, wikimon, wikital monsters)|date=2017-09-03|url=https://github.com/hatnote/wikimon|publisher=hatnote|access-date=2017-09-21}}
- Tahoe-LAFS, a distributed data store and distributed file system.
- Deluge, a highly modular BitTorrent client, uses Twisted.{{cite web|url=https://dev.deluge-torrent.org/wiki/Installing/Source|title=Deluge: build from source|website=dev.deluge-torrent.org|access-date=2020-01-08}}
- Magic Wormhole, a secure file transfer tool using PAKE.{{cite web|url=https://github.com/warner/magic-wormhole|title=Magic Wormhole|website=github.com}}
=Nevow=
{{Infobox software
| title =
| name = Nevow
| logo =
| screenshot =
| caption =
| collapsible =
| author = Donovan Preston[https://www.python.org/pycon/dc2004/papers/60/context this 2004 paper by Donovan Preston, the original author of Nevow and Formless] {{webarchive |url=https://web.archive.org/web/*/https://www.python.org/pycon/dc2004/papers/60/context |date=* }}[http://soundfarmer.com/content/nevow.html Nevow: A Web Application Construction Kit], Donovan Preston[http://article.gmane.org/gmane.comp.python.twisted/4973/ Subject: Re: ANN: Twisted 1.1.0, the framework of *your* internet], From: Donovan Preston, Date: 2003-10-27, Newsgroups: gmane.comp.python.twisted, nevow was originally a research project -- a weekend's worth of hacking whose benefits turned out to be so great that we decided to focus on bringing it up to a usable state for Quotient as soon as possible. And that's where it is now.
| developer = Divmod
| released = {{Start date and age|2004|05|06}}
| discontinued =
| latest release version = 0.14.4
| latest release date = {{Start date and age|2018|06|14}}{{cite web | url=https://github.com/twisted/nevow/releases | title= Releases · twisted/nevow | website= GitHub | access-date=2020-11-04 }}
| latest preview version =
| latest preview date =
| programming language = Python
| operating system = Cross-platform
| platform =
| size =
| language =
| genre = Web application framework
| license = MIT License
}}
Nevow (pronounced like the French nouveau) is a Python web application framework originally developed by the company Divmod. Template substitution is achieved via a small Tag Attribute Language, which is usually embedded in on-disk XML templates, though there is also a pure-Python domain-specific language called Stan, for expressing this markup programmatically. Nevow integrates well with Twisted.
Nevow was deployed on several high-profile web sites, most notably the official Python site.[https://wiki.python.org/moin/PythonWebsitePyramidDocs PythonWebsitePyramidDocs], Pyramid is the internal website templating system used to build the python.org pages. (It is not connected to the Pyramid web framework, formerly named BFG, that's used with Pylons.) Pyramid uses Nevow as its templating system and YAML as the format for its file based data - PythonInfo Wiki, python.org
As of mid-2010, Divmod went out of business,[http://glyph.twistedmatrix.com/2009/07/goodbye-divmod-hello-world.html Goodbye, Divmod. Hello, World!], July 10, 2009, Deciphering Glyph causing development work on Nevow to all but cease, and in 2011 its homepage was no longer accessible.[https://www.ohloh.net/p/nevow/commits Divmod Nevow commits] {{Webarchive|url=https://web.archive.org/web/20121015131618/https://www.ohloh.net/p/nevow/commits |date=2012-10-15 }} on Ohloh There is a project on Launchpad, hosting the source code of Divmod[http://divmod.org Divmod] {{webarchive|url=https://web.archive.org/web/20060813135423/http://divmod.org/ |date=August 13, 2006 }} including the source code of the Nevow project.[https://launchpad.net/divmod.org Divmod] on Launchpad
== Athena ==
Athena is a Nevow component which facilitates bi-directional, asynchronous communication between the Python and JavaScript portions of a web application in the form of remote procedure calls. This technique is typically called Ajax or Comet, though Nevow's implementation predates both of these labels.[http://divmodsphinx.funsize.net/nevow/chattutorial/#history History] {{Webarchive|url=https://web.archive.org/web/20160303203811/http://divmodsphinx.funsize.net/nevow/chattutorial/#history |date=2016-03-03 }}, Nevow Athena from Scratch, or The Evolution of a Chat Application — Divmod Nevow vtrunk documentation Athena also includes an inheritance-based JavaScript object system, which forms the basis of a client-side widget abstraction, module system and in-browser unit testing kit.
See also
{{Portal|Free and open-source software}}
- Application server
- Reactor pattern
- Perl Object Environment, a comparable framework for the Perl programming language
- Netty, for the Java programming language
- Node.js, for Javascript
- EventMachine, an event-processing library for Ruby{{cite web |url=http://rubyeventmachine.com/ |title=EventMachine |access-date=20 August 2011}}
- Kivy (framework), a multi-platform GUI framework (including iOS and Android){{cite web|url=http://kivy.org/docs/guide/other-frameworks.html|title=Integrating with other Frameworks — Kivy 1.11.0.dev0 documentation|website=kivy.org}}
References
{{Reflist}}
External links
- {{Official website}}
{{DEFAULTSORT:Twisted (software)}}
Category:Free network-related software
Category:Free software programmed in Python
Category:Python (programming language) libraries