Twisted (software)
Encyclopedia
Twisted is an event-driven
Event-driven programming
In computer programming, event-driven programming or event-based programming is a programming paradigm in which the flow of the program is determined by events—i.e., sensor outputs or user actions or messages from other programs or threads.Event-driven programming can also be defined as an...

 network programming
Computer network programming
In computing, network programming, essentially identical to socket programming or client–server programming, involves writing computer programs that communicate with other programs across a computer network. The program or process initiating the communication is called a client process, and the...

 framework
Software framework
In computer programming, a software framework is an abstraction in which software providing generic functionality can be selectively changed by user code, thus providing application specific software...

 written in Python
Python (programming language)
Python is a general-purpose, high-level programming language whose design philosophy emphasizes code readability. Python claims to "[combine] remarkable power with very clear syntax", and its standard library is large and comprehensive...

 and licensed under the MIT License
MIT License
The MIT License is a free software license originating at the Massachusetts Institute of Technology . It is a permissive license, meaning that it permits reuse within proprietary software provided all copies of the licensed software include a copy of the MIT License terms...

.

Twisted projects variously support TCP
Transmission Control Protocol
The Transmission Control Protocol is one of the core protocols of the Internet Protocol Suite. TCP is one of the two original components of the suite, complementing the Internet Protocol , and therefore the entire suite is commonly referred to as TCP/IP...

, UDP
User Datagram Protocol
The User Datagram Protocol is one of the core members of the Internet Protocol Suite, the set of network protocols used for the Internet. With UDP, computer applications can send messages, in this case referred to as datagrams, to other hosts on an Internet Protocol network without requiring...

, SSL/TLS
Transport Layer Security
Transport Layer Security and its predecessor, Secure Sockets Layer , are cryptographic protocols that provide communication security over the Internet...

, IP Multicast
IP Multicast
IP multicast is a method of sending Internet Protocol datagrams to a group of interested receivers in a single transmission. It is often employed for streaming media applications on the Internet and private networks. The method is the IP-specific version of the general concept of multicast...

, Unix domain sockets
Unix domain socket
A Unix domain socket or IPC socket is a data communications endpoint for exchanging data between processes executing within the same host operating system. While similar in functionality to...

, a large number of protocols (including HTTP, XMPP
Extensible Messaging and Presence Protocol
Extensible Messaging and Presence Protocol is an open-standard communications protocol for message-oriented middleware based on XML . The protocol was originally named Jabber, and was developed by the Jabber open-source community in 1999 for near-real-time, extensible instant messaging , presence...

, NNTP
Network News Transfer Protocol
The Network News Transfer Protocol is an Internet application protocol used for transporting Usenet news articles between news servers and for reading and posting articles by end user client applications...

, IMAP
Internet Message Access Protocol
Internet message access protocol is one of the two most prevalent Internet standard protocols for e-mail retrieval, the other being the Post Office Protocol...

, SSH
Secure Shell
Secure Shell is a network protocol for secure data communication, remote shell services or command execution and other secure network services between two networked computers that it connects via a secure channel over an insecure network: a server and a client...

, IRC, FTP
File Transfer Protocol
File Transfer Protocol is a standard network protocol used to transfer files from one host to another host over a TCP-based network, such as the Internet. FTP is built on a client-server architecture and utilizes separate control and data connections between the client and server...

, and others), and much more. Twisted is based on the event-driven programming
Event-driven programming
In computer programming, event-driven programming or event-based programming is a programming paradigm in which the flow of the program is determined by events—i.e., sensor outputs or user actions or messages from other programs or threads.Event-driven programming can also be defined as an...

 paradigm, which means that users of Twisted write short callbacks
Callback (computer science)
In computer programming, a callback is a reference to executable code, or a piece of executable code, that is passed as an argument to other code. This allows a lower-level software layer to call a subroutine defined in a higher-level layer....

 which are called by the framework.

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 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
Exception handling
Exception handling is a programming language construct or computer hardware mechanism designed to handle the occurrence of exceptions, special conditions that change the normal flow of program execution....

) 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
Future (programming)
In computer science, future, promise, and delay refer to constructs used for synchronization in some concurrent programming languages. They describe an object that acts as a proxy for a result that is initially not known, usually because the computation of its value has not yet completed.The term...

). A deferred is a value which has not been computed yet, for example because it needs 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 transferred through the callback chain, with the result of each callback being the input for the next one. This allows operating on the values of a deferred without knowing what they are. For example, if a deferred returns a string from a remote peer containing an IP address
IP address
An Internet Protocol address is a numerical label assigned to each device participating in a computer network that uses the Internet Protocol for communication. An IP address serves two principal functions: host or network interface identification and location addressing...

 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 is 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 which looks as though it is serial, while still maintaining the event-driven abstraction.

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+
GTK+ is a cross-platform widget toolkit for creating graphical user interfaces. It is licensed under the terms of the GNU LGPL, allowing both free and proprietary software to use it. It is one of the most popular toolkits for the X Window System, along with Qt.The name GTK+ originates from GTK;...

, Qt and Cocoa
Cocoa (API)
Cocoa is Apple's native object-oriented application programming interface for the Mac OS X operating system and—along with the Cocoa Touch extension for gesture recognition and animation—for applications for the iOS operating system, used on Apple devices such as the iPhone, the iPod Touch, and...

 (through PyObjC
PyObjC
PyObjC is a bidirectional bridge between Python and Objective-C. It allows Python scripts to use and extend existing Objective-C class libraries....

). This allows using Twisted as the networking support layer in graphical user interface
Graphical user interface
In computing, a graphical user interface is a type of user interface that allows users to interact with electronic devices with images rather than text commands. GUIs can be used in computers, hand-held devices such as MP3 players, portable media players or gaming devices, household appliances and...

 (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
BuildBot
BuildBot is a software development continuous integration tool which automates the compile/test cycle required to validate changes to the project code base...

 continuous-integration system relies on Twisted for client/server communication.

ITA Software
ITA Software
ITA Software is a travel industry software company in Cambridge, Massachusetts. The company was founded by computer scientists from the MIT Artificial Intelligence Laboratory in 1996. On July 1, 2010 ITA agreed to be acquired by Google. On April 8th, 2011 the US Department of Justice approved the...

 has developed an airline-reservation system for Air Canada
Air Canada
Air Canada is the flag carrier and largest airline of Canada. The airline, founded in 1936, provides scheduled and charter air transport for passengers and cargo to 178 destinations worldwide. It is the world's tenth largest passenger airline by number of destinations, and the airline is a...

 that uses Twisted extensively.

Sage, an open-source alternative to Mathematica
Mathematica
Mathematica is a computational software program used in scientific, engineering, and mathematical fields and other areas of technical computing...

, Maple
Maple
Acer is a genus of trees or shrubs commonly known as maple.Maples are variously classified in a family of their own, the Aceraceae, or together with the Hippocastanaceae included in the family Sapindaceae. Modern classifications, including the Angiosperm Phylogeny Group system, favour inclusion in...

, Magma
Magma
Magma is a mixture of molten rock, volatiles and solids that is found beneath the surface of the Earth, and is expected to exist on other terrestrial planets. Besides molten rock, magma may also contain suspended crystals and dissolved gas and sometimes also gas bubbles. Magma often collects in...

, Matlab
MATLAB
MATLAB is a numerical computing environment and fourth-generation programming language. Developed by MathWorks, MATLAB allows matrix manipulations, plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs written in other languages,...

, has a web-based interface, Sage notebook, that runs on a Twisted server.

Twisted was used in the Omegle
Omegle
Omegle is an online chat website that allows users to communicate with strangers without registering. The service randomly pairs users up into one-on-one chat sessions where they chat anonymously using the handles "You" and "Stranger"...

 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
NASA
The National Aeronautics and Space Administration is the agency of the United States government that is responsible for the nation's civilian space program and for aeronautics and aerospace research...

.

The original version of social networking and microblogging site Jaiku
Jaiku
Jaiku is a social networking, micro-blogging and lifestreaming service comparable to Twitter. Jaiku was founded in February 2006 by Jyri Engeström and Petteri Koponen from Finland and launched in July of that year...

 used Twisted.

FluidDB, an online cloud data-store, uses Twisted extensively for internal RPC (partly in combination with Thrift
Thrift (protocol)
Thrift is an interface definition language that is used to define and create services for numerous languages. It is used as a remote procedure call framework and was developed at Facebook for "scalable cross-language services development"...

 and AMQP), for its internal services, and for external APIs.

The file-hosting service Ubuntu One
Ubuntu One
Ubuntu One is a personal cloud service operated by Canonical Ltd.The service enables users to store files online and sync them between computers and mobile devices, as well as stream audio and music from cloud to mobile devices.- Features :...

 uses Twisted.

Cloudkick
Cloudkick
Cloudkick is a cloud server management and monitoring SaaS based out of San Francisco. Cloudkick's products include a centralized server monitoring tool for multiple cloud server providers, as well as dynamic server management tools...

, a cloud-server management web-application, uses Twisted Python.

Twilio
Twilio
Twilio is a cloud communications IaaS company based in San Francisco, California. Twilio allows software developers to programmatically make and receive phone calls and send and receive text messages using its web service APIs...

, a cloud telephony provider uses Twisted.

The site http://twistedmatrix.com/trac/wiki/SuccessStories lists some users of Twisted Python.

See also

  • Perl Object Environment
    Perl Object Environment
    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 Architecture: Layers of Abstraction :...

    , a comparable framework for the Perl
    Perl
    Perl is a high-level, general-purpose, interpreted, dynamic programming language. Perl was originally developed by Larry Wall in 1987 as a general-purpose Unix scripting language to make report processing easier. Since then, it has undergone many changes and revisions and become widely popular...

     programming language
  • JBoss Netty
    JBoss Netty
    JBoss Netty is a New I/O client-server framework for the development of Java network applications such as protocol servers and clients. The asynchronous event-driven network application framework and tools is used to simplify network programming such as TCP and UDP socket servers. Netty includes...

    , for the Java programming language
  • Node.js
    Node.js
    Node.js is a software system designed for writing highly-scalable internet applications, notably web servers.Programs are written in JavaScript, using event-driven, asynchronous I/O to minimize overhead and maximize scalability....

    , an event-driven I/O framework for the V8 JavaScript engine.
  • EventMachine, an event-processing library for Ruby
    Ruby (programming language)
    Ruby is a dynamic, reflective, general-purpose object-oriented programming language that combines syntax inspired by Perl with Smalltalk-like features. Ruby originated in Japan during the mid-1990s and was first developed and designed by Yukihiro "Matz" Matsumoto...

    .
The source of this article is wikipedia, the free encyclopedia.  The text of this article is licensed under the GFDL.
 
x
OK