HOME

TheInfoList



OR:

Twisted is an event-driven network programming framework written in Python and licensed under the
MIT License The MIT License is a permissive software license originating at the Massachusetts Institute of Technology (MIT) in the late 1980s. As a permissive license, it puts very few restrictions on reuse and therefore has high license compatibility. Unl ...
. 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 HTTP (Hypertext Transfer Protocol) 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 Web, wher ...
,
XMPP Extensible Messaging and Presence Protocol (abbreviation XMPP, originally named Jabber) is an Open standard, open communication protocol designed for instant messaging (IM), presence information, and contact list maintenance. Based on XML (Ext ...
, NNTP,
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 IRC (Internet Relay Chat) is a text-based chat system for instant messaging. IRC is designed for group communication in discussion forums, called '' channels'', but also allows one-on-one communication via private messages as well as chat ...
,
FTP The File Transfer Protocol (FTP) is a standard communication protocol used for the transfer of computer files from a server to a client on a computer network. FTP is built on a client–server model architecture using separate control and dat ...
, 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 Control flow, flow of the program is determined by external Event (computing), events. User interface, UI events from computer mouse, mice, computer keyboard, ...
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 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. Today, POP version 3 (POP3) is the most commonly used version. Together with IMAP, i ...
) 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 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 currently ex ...
''). 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 assigned to a device connected to a computer network that uses the Internet Protocol for communication. IP addresses serve two main functions: network interface i ...
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 software 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 proprietary s ...
, Qt and Cocoa (through PyObjC). This allows using Twisted as the network layer in
graphical user interface A graphical user interface, or GUI, is a form of user interface that allows user (computing), users to human–computer interaction, interact with electronic devices through Graphics, graphical icon (computing), icons and visual indicators such ...
(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 size and passengers carried. Air Canada is headquartered in the borough of Saint-Laurent in the city of Montreal. The airline, founded in 1937, provides scheduled and cha ...
that uses Twisted extensively. *
SageMath SageMath (previously Sage or SAGE, "System for Algebra and Geometry Experimentation") is a computer algebra system (CAS) with features covering many aspects of mathematics, including algebra, combinatorics, graph theory, group theory, differentia ...
, an open-source alternative to
Mathematica Wolfram (previously known as Mathematica and Wolfram Mathematica) is a software system with built-in libraries for several areas of technical computing that allows machine learning, statistics, symbolic computation, data manipulation, network ...
,
Maple ''Acer'' is a genus of trees and shrubs commonly known as maples. The genus is placed in the soapberry family Sapindaceae.Stevens, P. F. (2001 onwards). Angiosperm Phylogeny Website. Version 9, June 2008 nd more or less continuously updated si ...
,
Magma Magma () is the molten or semi-molten natural material from which all igneous rocks are formed. Magma (sometimes colloquially but incorrectly referred to as ''lava'') is found beneath the surface of the Earth, and evidence of magmatism has also ...
,
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 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 agencies of the United States government, independent agency of the federal government of the United States, US federal government responsible for the United States ...
. *
Conch Conch ( , , ) is a common name of a number of different medium-to-large-sized sea snails. Conch shells typically have a high Spire (mollusc), spire and a noticeable siphonal canal (in other words, the shell comes to a noticeable point on both ...
, an implementation of the
Secure Shell The Secure Shell Protocol (SSH Protocol) 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 was designed for ...
(SSH) protocol * The original version of social networking and microblogging site Jaiku used Twisted. * 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 Ubuntu One is an OpenID-based single sign-on service operated by Canonical Ltd. to allow users to log onto many Canonical-owned Web sites. Until April 2014, Ubuntu One was also a file hosting service and music store that allowed users to store ...
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. * Velocity Weather, a meteorological data processing and integration API is built on Twisted. * 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 Listen to Wikipedia is a multimedia visualizer developed by Mahmoud Hashemi and Stephen LaPorte which translates Special:RecentChanges, recent Wikipedia edits into a display of visuals and sounds. The Open-source software, open source Software, ...
, a
Wikipedia Wikipedia is a free content, free Online content, online encyclopedia that is written and maintained by a community of volunteers, known as Wikipedians, through open collaboration and the wiki software MediaWiki. Founded by Jimmy Wales and La ...
audio-visualizer, uses Twisted to broadcast real-time edit events to browsers. * Tahoe-LAFS, a distributed data store and distributed file system. *
Deluge A deluge is a large downpour of rain, often a flood. The Deluge refers to the flood narrative in the biblical book of Genesis. Deluge or Le Déluge may also refer to: History *Deluge (history), the Swedish and Russian invasion of the Polish-L ...
, a highly modular
BitTorrent BitTorrent is a Protocol (computing), communication protocol for peer-to-peer file sharing (P2P), which enables users to distribute data and electronic files over the Internet in a Decentralised system, decentralized manner. The protocol is d ...
client, uses Twisted. * Magic Wormhole, a secure file transfer tool using PAKE.


Nevow

Nevow (pronounced like the French ''nouveau'') is a Python
web application framework A web framework (WF) or web application framework (WAF) is a software framework that is designed to support the development of web applications including web services, web resources, and web APIs. Web frameworks provide a standard way to build and ...
originally developed by the company Divmod. Template substitution is achieved via a small Tag Attribute Language, which is usually embedded in on-disk
XML Extensible Markup Language (XML) is a markup language and file format for storing, transmitting, and reconstructing data. It defines a set of rules for encoding electronic document, documents in a format that is both human-readable and Machine-r ...
templates, though there is also a pure-Python
domain-specific language A domain-specific language (DSL) is a computer language specialized to a particular application domain. This is in contrast to a general-purpose language (GPL), which is broadly applicable across domains. There are a wide variety of DSLs, ranging ...
called Stan, for expressing this markup programmatically. Nevow integrates well with Twisted. Nevow was deployed on several high-profile
web site A website (also written as a web site) is any web page whose content is identified by a common domain name and is published on at least one web server. Websites are typically dedicated to a particular topic or purpose, such as news, education, ...
s, most notably the official Python site. As of mid-2010, Divmod went out of business, causing development work on Nevow to all but cease, and in 2011 its homepage was no longer accessible. There is a project on Launchpad, hosting the source code of Divmod including the source code of the Nevow project.


Athena

Athena is a Nevow component which facilitates bi-directional,
asynchronous communication In telecommunications, asynchronous communication is transmission of data, generally without the use of an external clock signal, where data can be transmitted intermittently rather than in a steady stream. Any timing required to recover data fro ...
between the Python and
JavaScript JavaScript (), often abbreviated as JS, is a programming language and core technology of the World Wide Web, alongside HTML and CSS. Ninety-nine percent of websites use JavaScript on the client side for webpage behavior. Web browsers have ...
portions of a web application in the form of
remote procedure call In distributed computing, a remote procedure call (RPC) is when a computer program causes a procedure (subroutine) to execute in a different address space (commonly on another computer on a shared computer network), which is written as if it were a ...
s. This technique is typically called
Ajax Ajax may refer to: Greek mythology and tragedy * Ajax the Great, a Greek mythological hero, son of King Telamon and Periboea * Ajax the Lesser, a Greek mythological hero, son of Oileus, the king of Locris * Ajax (play), ''Ajax'' (play), by the an ...
or
Comet A comet is an icy, small Solar System body that warms and begins to release gases when passing close to the Sun, a process called outgassing. This produces an extended, gravitationally unbound atmosphere or Coma (cometary), coma surrounding ...
, though Nevow's implementation predates both of these labels. Athena also includes an
inheritance Inheritance is the practice of receiving private property, titles, debts, entitlements, privileges, rights, and obligations upon the death of an individual. The rules of inheritance differ among societies and have changed over time. Offi ...
-based JavaScript object system, which forms the basis of a client-side '' widget'' abstraction, module system and in- browser
unit test Unit testing, component or module testing, is a form of software testing by which isolated source code is tested to validate expected behavior. Unit testing describes tests that are run at the unit-level to contrast testing at the integration ...
ing kit.


See also

*
Application server An application server is a server that hosts applications or software that delivers a business application through a communication protocol. For a typical web application, the application server sits behind the web servers. An application ser ...
*
Reactor pattern The reactor software design pattern is an event handling strategy that can respond to many potential service requests concurrently. The pattern's key component is an event loop, running in a ''single'' thread or process, which demultiplexes inc ...
* Perl Object Environment, a comparable framework for the
Perl Perl is a high-level, general-purpose, interpreted, dynamic programming language. Though Perl is not officially an acronym, there are various backronyms in use, including "Practical Extraction and Reporting Language". Perl was developed ...
programming language * Netty, for the Java programming language * Node.js, for Javascript * EventMachine, an event-processing library for
Ruby 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 sapph ...
* Kivy (framework), 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