HOME

TheInfoList



OR:

Twisted is an event-driven network programming
framework A framework is a generic term commonly referring to an essential supporting structure which other things are built on top of. Framework may refer to: Computing * Application framework, used to implement the structure of an application for an op ...
written in Python and licensed under the
MIT License The MIT License is a permissive free software license originating at the Massachusetts Institute of Technology (MIT) in the late 1980s. As a permissive license, it puts only very limited restriction on reuse and has, therefore, high license comp ...
. Twisted projects variously support TCP, UDP, SSL/TLS,
IP multicast IP multicast is a method of sending Internet Protocol (IP) datagrams to a group of interested receivers in a single transmission. It is the IP-specific form of multicast and is used for streaming media and other network applications. It uses speci ...
, Unix domain sockets, many protocols (including
HTTP The Hypertext Transfer Protocol (HTTP) is an application layer protocol in the Internet protocol suite model for distributed, collaborative, hypermedia information systems. HTTP is the foundation of data communication for the World Wide We ...
,
XMPP Extensible Messaging and Presence Protocol (XMPP, originally named Jabber) is an open communication protocol designed for instant messaging (IM), presence information, and contact list maintenance. Based on XML (Extensible Markup Language), i ...
,
NNTP The Network News Transfer Protocol (NNTP) is an application protocol used for transporting Usenet news articles (''netnews'') between news servers, and for reading/posting articles by the end user client applications. Brian Kantor of the Univers ...
,
IMAP In computing, the Internet Message Access Protocol (IMAP) is an Internet standard protocol used by email clients to retrieve email messages from a mail server over a TCP/IP connection. IMAP is defined by . IMAP was designed with the goal of per ...
, SSH, IRC, FTP, and others), and much more. Twisted is based on the
event-driven programming In computer programming, event-driven programming is a programming paradigm in which the flow of the program is determined by events such as user actions (mouse clicks, key presses), sensor outputs, or message passing from other programs or thr ...
paradigm, which means that users of Twisted write short
callbacks In computer programming, a callback or callback function is any reference to executable code that is passed as an argument to another piece of code; that code is expected to ''call back'' (execute) the callback function as part of its job. Thi ...
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 In computing, the Post Office Protocol (POP) is an application-layer Internet standard protocol used by e-mail clients to retrieve e-mail from a mail server. POP version 3 (POP3) is the version in common use, and along with IMAP the most common ...
) and physical 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 The future is the time after the past and present. Its arrival is considered inevitable due to the existence of time and the laws of physics. Due to the apparent nature of reality and the unavoidability of the future, everything that current ...
''). 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 An Internet Protocol address (IP address) is a numerical label such as that is connected to a computer network that uses the Internet Protocol for communication.. Updated by . An IP address serves two main functions: network interface ident ...
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+ GTK (formerly GIMP ToolKit and GTK+) is a free and open-source cross-platform widget toolkit for creating graphical user interfaces (GUIs). It is licensed under the terms of the GNU Lesser General Public License, allowing both free and prop ...
, Qt and
Cocoa Cocoa may refer to: Chocolate * Chocolate * ''Theobroma cacao'', the cocoa tree * Cocoa bean, seed of ''Theobroma cacao'' * Chocolate liquor, or cocoa liquor, pure, liquid chocolate extracted from the cocoa bean, including both cocoa butter an ...
(through PyObjC). This allows using Twisted as the network layer in
graphical user interface The GUI ( "UI" by itself is still usually pronounced . or ), graphical user interface, is a form of user interface that allows users to interact with electronic devices through graphical icons and audio indicator such as primary notation, ins ...
(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

* The BuildBot continuous-integration system relies on Twisted for client/server communication. *
ITA Software ITA Software is a travel industry software division of Google, formerly an independent company, in Cambridge, Massachusetts. The company was founded by Jeremy Wertheimer, a computer scientist from the MIT Artificial Intelligence Laboratory and Co ...
has developed an airline-reservation system for
Air Canada Air Canada is the flag carrier and the largest airline of Canada by the size and passengers carried. Air Canada maintains its headquarters in the borough of Saint-Laurent, Montreal, Quebec. The airline, founded in 1937, provides scheduled an ...
that uses Twisted extensively. * SageMath, an open-source alternative to
Mathematica Wolfram Mathematica is a software system with built-in libraries for several areas of technical computing that allow machine learning, statistics, symbolic computation, data manipulation, network analysis, time series analysis, NLP, optimiza ...
,
Maple ''Acer'' () is a genus of trees and shrubs commonly known as maples. The genus is placed in the family Sapindaceae.Stevens, P. F. (2001 onwards). Angiosperm Phylogeny Website. Version 9, June 2008 nd more or less continuously updated since h ...
,
Magma Magma () is the molten or semi-molten natural material from which all igneous rocks are formed. Magma is found beneath the surface of the Earth, and evidence of magmatism has also been discovered on other terrestrial planets and some natura ...
,
MATLAB MATLAB (an abbreviation of "MATrix LABoratory") is a proprietary multi-paradigm programming language and numeric computing environment developed by MathWorks. MATLAB allows matrix manipulations, plotting of functions and data, implementat ...
, has a web-based interface, SageMath notebook, that runs on a Twisted server. * Twisted was used in the
Omegle Omegle is a free online chat website that allows users to socialize with others without the need to register. The service randomly pairs users in one-on-one chat sessions where they chat anonymously using the names "You" and "Stranger" or "Str ...
one-on-one chat service until it was replaced with gevent for performance reasons. * The Apple Calendar Server uses Twisted, as do some internal projects of
NASA The National Aeronautics and Space Administration (NASA ) is an independent agency of the US federal government responsible for the civil space program, aeronautics research, and space research. NASA was established in 1958, succeedin ...
. *
Conch Conch () is a common name of a number of different medium-to-large-sized sea snails. Conch shells typically have a high spire and a noticeable siphonal canal (in other words, the shell comes to a noticeable point at both ends). In North Am ...
, an implementation of the
Secure Shell The Secure Shell Protocol (SSH) is a cryptographic network protocol for operating network services securely over an unsecured network. Its most notable applications are remote login and command-line execution. SSH applications are based ...
(SSH) protocol * The original version of social networking and microblogging site
Jaiku Jaiku was a social networking, micro-blogging and lifestreaming service comparable to Twitter, founded a month before the latter. Jaiku was founded in February 2006 by Jyri Engeström and Petteri Koponen from Finland and launched in July of that y ...
used Twisted. * Fluidinfo, an online cloud data-store, uses Twisted extensively for internal RPC (partly in combination with Thrift and
AMQP The Advanced Message Queuing Protocol (AMQP) is an open standard application layer protocol for message-oriented middleware. The defining features of AMQP are message orientation, queuing, routing (including point-to-point and publish-and-subsc ...
), for its internal services, and for external APIs. * The file-hosting service Ubuntu One used Twisted. *
Tor2web Tor2web (pronounced "Tor to Web") is a software project to allow Tor hidden services to be accessed from a standard browser without being connected to the Tor network. It was created by Aaron Swartz and Virgil Griffith. History Tor is a net ...
, an HTTP proxy for Tor Hidden Services (HS), uses Twisted. *
GlobaLeaks GlobaLeaks is an open-source, free software intended to enable secure and anonymous whistleblowing initiatives. History The project started on 15 December 2010 and the first software prototype was announced on 6 September 2011. Relevant figure ...
, an open-source whistleblowing framework, uses Twisted. *
Cloudkick Rackspace Technology, Inc. is an American cloud computing company based in Windcrest, Texas, an inner suburb of San Antonio, Texas. The company also has offices in Blacksburg, Virginia, and Austin, Texas, as well as in Australia, Canada, United ...
, a cloud-server management web-application, used Twisted. It now has been rewritten using
Node.js Node.js is an open-source server environment. Node.js is cross-platform and runs on Windows, Linux, Unix, and macOS. Node.js is a back-end JavaScript runtime environment. Node.js runs on the V8 JavaScript Engine and executes JavaScript cod ...
. *
Twilio Twilio () is an American company based in San Francisco, California, which provides programmable communication tools for making and receiving phone calls, sending and receiving text messages, and performing other communication functions using i ...
, a cloud telephony provider, uses Twisted. * Twitch, a video game broadcasting and chat community, uses Twisted. * Velocity Weather, a meteorological data processing and integration API is built on Twisted. * qwebirc, a web-based IRC client, uses Twisted. *
Zenoss Core The company Zenoss, Inc. was founded in 2005 and is headquartered in Austin, Texas. The company develops hybrid IT monitoring and analytics software. Zenoss Community Edition was a free and open-source application, server, and network management ...
, a network management platform, uses Twisted for many internal and collection daemons. * Scrapy, a web crawler based on Twisted. *
Listen to Wikipedia Listen to Wikipedia, also known as L2W or Hatnote: Listen To Wikipedia, is a multimedia visualizer developed by Mahmoud Hashemi and Stephen LaPorte which translates recent Wikipedia edits into a display of visuals and sounds. The open source sof ...
, a
Wikipedia Wikipedia is a multilingual free online encyclopedia written and maintained by a community of volunteers, known as Wikipedians, through open collaboration and using a wiki-based editing system. Wikipedia is the largest and most-read refer ...
audio-visualizer, uses Twisted to broadcast real-time edit events to browsers. *
Tahoe-LAFS Tahoe-LAFS (Tahoe Least-Authority File Store) is a free and open, secure, decentralized, fault-tolerant, distributed data store and distributed file system. It can be used as an online backup system, or to serve as a file or Web host similar t ...
, a distributed data store and distributed file system. * Deluge, a highly modular BitTorrent client, uses Twisted. *
Magic Wormhole Magic or Magick most commonly refers to: * Magic (supernatural), beliefs and actions employed to influence supernatural beings and forces * Ceremonial magic, encompasses a wide variety of rituals of magic * Magical thinking, the belief that unrela ...
, a secure file transfer tool using PAKE.


See also

*
Application server An application server is a server that hosts applications or software that delivers a business application through a communication protocol. An application server framework is a service layer model. It includes software components available to a ...
* Reactor pattern *
Perl Object Environment : ''For the Mach variant, see Mach (kernel)'' The Perl Object Environment or POE is a library of Perl modules written in the Perl programming language by Rocco Caputo et al. From CPAN: :''"POE originally was developed as the core of a persisten ...
, a comparable framework for the
Perl Perl is a family of two high-level, general-purpose, interpreted, dynamic programming languages. "Perl" refers to Perl 5, but from 2000 to 2019 it also referred to its redesigned "sister language", Perl 6, before the latter's name was offic ...
programming language *
Netty Netty may refer to: * Netty (software), a Java project * North East England ( Geordie) dialect for toilet or public convenience * Netty (name) See also * Westoe Netty * Nethy (disambiguation) * Natty (disambiguation) *Netta (disambiguation) * N ...
, for the Java programming language *
Node.js Node.js is an open-source server environment. Node.js is cross-platform and runs on Windows, Linux, Unix, and macOS. Node.js is a back-end JavaScript runtime environment. Node.js runs on the V8 JavaScript Engine and executes JavaScript cod ...
, for Javascript *
EventMachine EventMachine is a software system designed for writing highly scalable applications for Ruby. It provides event-driven I/O using the reactor pattern. EventMachine is the most popular library for concurrent computing in the Ruby programming langua ...
, an event-processing library for
Ruby A ruby is a pinkish red to blood-red colored gemstone, a variety of the mineral corundum ( aluminium oxide). Ruby is one of the most popular traditional jewelry gems and is very durable. Other varieties of gem-quality corundum are called ...
*
Kivy (framework) Kivy is a free and open source Python framework for developing mobile apps and other multitouch application software with a natural user interface (NUI). It is distributed under the terms of the MIT License, and can run on Android, iOS, L ...
, a multi-platform GUI framework (including iOS and Android)


References


External links

* {{DEFAULTSORT:Twisted (software) Free network-related software Free software programmed in Python Free system software Python (programming language) libraries Python (programming language) software Software using the MIT license