Twisted
Installing Twisted
Installing Optional Dependencies
Twisted Core
Developer Guides
The Vision For Twisted
Writing Servers
Overview
Protocols
Factories
Putting it All Together
Writing Clients
Overview
Protocol
Simple, single-use clients
ClientFactory
A Higher-Level Example: ircLogBot
Further Reading
Test-driven development with Twisted
Introductory example of Python unit testing
Creating an API and writing tests
Making the tests pass
Twisted specific testing
Testing a protocol
More good practices
Resolve a bug
Testing Deferreds without the reactor
Dropping into a debugger
Code coverage
Conclusion
Twisted from Scratch, or The Evolution of Finger
The Evolution of Finger: building a simple finger service
The Evolution of Finger: adding features to the finger service
The Evolution of Finger: cleaning up the finger code
The Evolution of Finger: moving to a component based architecture
The Evolution of Finger: pluggable backends
The Evolution of Finger: a web frontend
The Evolution of Finger: Twisted client support using Perspective Broker
The Evolution of Finger: using a single factory for multiple protocols
The Evolution of Finger: a Twisted finger client
The Evolution of Finger: making a finger library
The Evolution of Finger: configuration and packaging of the finger service
Introduction
Contents
The Evolution of Finger: building a simple finger service
Introduction
Refuse Connections
Do Nothing
Drop Connections
Read Username, Drop Connections
Read Username, Output Error, Drop Connections
Output From Empty Factory
Output from Non-empty Factory
Use Deferreds
Run ‘finger’ Locally
Read Status from the Web
Use Application
twistd
The Evolution of Finger: adding features to the finger service
Introduction
Setting Message By Local Users
Use Services to Make Dependencies Sane
Read Status File
Announce on Web, Too
Announce on IRC, Too
Add XML-RPC Support
The Evolution of Finger: cleaning up the finger code
Introduction
Write Readable Code
The Evolution of Finger: moving to a component based architecture
Introduction
Write Maintainable Code
Advantages of Latest Version
Aspect-Oriented Programming
The Evolution of Finger: pluggable backends
Introduction
Another Back-end
Yet Another Back-end: Doing the Standard Thing
The Evolution of Finger: a web frontend
Introduction
The Evolution of Finger: Twisted client support using Perspective Broker
Introduction
Use Perspective Broker
The Evolution of Finger: using a single factory for multiple protocols
Introduction
Support HTTPS
The Evolution of Finger: a Twisted finger client
Introduction
Finger Proxy
The Evolution of Finger: making a finger library
Introduction
Organization
Easy Configuration
The Evolution of Finger: configuration and packaging of the finger service
Introduction
Plugins
OS Integration
Setting up the TwistedQuotes application
Goal
Setting up the TwistedQuotes project directory
Designing Twisted Applications
Goals
Example of a modular design: TwistedQuotes
Overview of Twisted Internet
Reactor Overview
Reactor Basics
Using the reactor object
Using TLS in Twisted
Overview
TLS echo server and client
Using startTLS
Client authentication
Related facilities
Conclusion
UDP Networking
Overview
DatagramProtocol
Adopted Datagram Ports
Connected UDP
Multicast UDP
Broadcast UDP
IPv6
Using Processes
Overview
Running Another Process
Writing a ProcessProtocol
Things that can happen to your ProcessProtocol
Things you can do from your ProcessProtocol
Verbose Example
Doing it the Easy Way
Mapping File Descriptors
Introduction to Deferreds
The joy of order
A hypothetical problem
The components of a solution
One solution: Deferred
Getting it right: The failure cases
Conclusion
Deferred Reference
Deferreds
Callbacks
Errbacks
Handling either synchronous or asynchronous results
Cancellation
DeferredList
Class Overview
See also
Generating Deferreds
Class overview
What Deferreds don’t do: make your code asynchronous
Advanced Processing Chain Control
Returning Deferreds from synchronous functions
Integrating blocking code with Twisted
Possible sources of error
Scheduling tasks for the future
Using Threads in Twisted
Running code in a thread-safe manner
Running code in threads
Utility Methods
Managing the Thread Pool
Producers and Consumers: Efficient High-Volume Streaming
Push Producers
Pull Producers
Consumers
Further Reading
Choosing a Reactor and GUI Toolkit Integration
Overview
Reactor Functionality
General Purpose Reactors
Platform-Specific Reactors
GUI Integration Reactors
Non-Reactor GUI Integration
Getting Connected with Endpoints
Introduction
Constructing and Using Endpoints
Maximizing the Return on your Endpoint Investment
Endpoint Types Included With Twisted
Components: Interfaces and Adapters
Interfaces and Components in Twisted code
Cred: Pluggable Authentication
Goals
Cred objects
Responsibilities
Cred plugins
Conclusion
The Twisted Plugin System
Writing Extensible Programs
Extending an Existing Program
Alternate Plugin Packages
Plugin Caching
Further Reading
The Basics
Application
twistd
OS Integration
Using the Twisted Application Framework
Introduction
Overview
Using Services and Application
Writing a twistd Plugin
Goals
Alternatives to twistd plugins
Creating the plugin
Using cred with your TAP
Conclusion
Deploying Twisted with systemd
Introduction
Prerequisites
Basic Systemd Service Configuration
Socket Activation
Conclusion
Limitations and Known Issues
Further Reading
Logging with twisted.python.log
Basic usage
Writing log observers
Customizing
twistd
logging
Symbolic Constants
Overview
Constant Names
Constants With Values
Constants As Flags
twisted.enterprise.adbapi: Twisted RDBMS support
Abstract
What you should already know
Quick Overview
How do I use adbapi?
Examples of various database adapters
And that’s it!
Parsing command-lines with usage.Options
Introduction
Boolean Options
Parameters
Option Subcommands
Generic Code For Options
Parsing Arguments
Post Processing
Type enforcement
Shell tab-completion
DirDBM: Directory-based Storage
dirdbm.DirDBM
dirdbm.Shelf
Writing tests for Twisted code using Trial
Trial basics
Trial directories
Twisted-specific quirks: reactor, Deferreds, callLater
Extremely Low-Level Socket Operations
Introduction
Sending And Receiving Regular Data
Copying File Descriptors
Setting Up
Commands
Locators
Box Receivers
Overview of Twisted Spread
Rationale
Introduction to Perspective Broker
Introduction
Object Roadmap
Things you can Call Remotely
Things you can Copy Remotely
Using Perspective Broker
Basic Example
Complete Example
References can come back to you
References to client-side objects
Raising Remote Exceptions
Try/Except blocks and Failure.trap
Managing Clients of Perspectives
Overview
Managing Avatars
Managing Clients
PB Copyable: Passing Complex Types
Overview
Motivation
Passing Objects
pb.Copyable
pb.Cacheable
Authentication with Perspective Broker
Overview
Compartmentalizing Services
Avatars and Perspectives
Perspective Examples
Using Avatars
PB Limits
Banana Limits
Perspective Broker Limits
Porting to Python 3
Introduction
API Differences
Byte Strings and Text Strings
Twisted Positioning
Introduction
High-level overview
Examples
Twisted Glossary
Debugging Python(Twisted) with Emacs
Examples
Simple Echo server and client
Chat
Echo server & client variants
AMP server & client variants
Perspective Broker
Cred
GUI
FTP examples
Logging
POSIX Specific Tricks
Miscellaneous
Specifications
Banana Protocol Specifications
Introduction
Banana Encodings
Element Types
Profiles
Protocol Handshake and Behaviour
Development of Twisted
Naming Conventions
Philosophy
Abstraction Levels
Learning Curves
Security
Bad input
Resource Exhaustion and DoS
Twisted Development Policy
Twisted Coding Standard
HTML Documentation Standard for Twisted
Twisted Writing Standard
Unit Tests in Twisted
Working from Twisted’s Subversion repository
Twisted Conch
Developer Guides
Writing a client with Twisted Conch
Introduction
Using an SSH Command Endpoint
Writing a client
The Transport
The Authorization Client
The Connection
The Channel
The main() function
Examples
Simple SSH server and client
Simple telnet server
twisted.conch.insults examples
Twisted Lore
Developer Guides
Using the Lore Documentation System
Writing Lore Documents
Writing Lore XHTML Templates
Using Lore to Generate HTML
Using Lore to Generate LaTex
Using Lore to Generate Slides
Linting
Extending the Lore Documentation System
Overview
Inputs and Outputs
Examples
Twisted Mail
Examples
SMTP servers
SMTP clients
IMAP clients
Twisted Mail Tutorial: Building an SMTP Client from Scratch
Introduction
SMTP Client 1
SMTP Client 2
SMTP Client 3
SMTP Client 4
SMTP Client 5
SMTP Client 6
SMTP Client 7
SMTP Client 8
SMTP Client 9
SMTP Client 10
SMTP Client 11
Twisted Names
Developer Guides
A Guided Tour of twisted.names.client
Using the Global Resolver
Creating a New Resolver
Installing a Resolver in the Reactor
Lower Level APIs
Further Reading
Creating and working with a names (DNS) server
Creating a non-authoritative server
Creating an authoritative server
Creating a custom server
A simple forwarding DNS server
A server which computes responses dynamically
Further Reading
Examples
DNS (Twisted Names)
Twisted Pair
Developer Guides
Twisted Pair: Tunnels And Network Taps
Tuntap Ports
Twisted Pair: Device Configuration
Twisted Pair’s Test Suite
Examples
Miscellaneous
Twisted Web
Developer Guides
Overview of Twisted Web
Introduction
Twisted Web’s Structure
Resources
Web programming with Twisted Web
Configuring and Using the Twisted Web Server
Twisted Web Development
Advanced Configuration
Running a Twisted Web Server
Rewriting URLs
Knowing When We’re Not Wanted
As-Is Serving
Web Application Development
Code layout
Web application deployment
Understanding resource scripts (
.rpy
files)
HTML Templating with twisted.web.template
A Very Quick Introduction To Templating In Python
twisted.web.template - Why And How you Might Want to Use It
Quoting
Deferreds
A Brief Note on Formats and DOCTYPEs
A Bit of History
Creating XML-RPC Servers and Clients with Twisted
Introduction
Creating a XML-RPC server
SOAP Support
Creating an XML-RPC Client
Serving SOAP and XML-RPC simultaneously
Twisted Web In 60 Seconds
Serving Static Content From a Directory
Generating a Page Dynamically
Static URL Dispatch
Dynamic URL Dispatch
Error Handling
Custom Response Codes
Handling POSTs
Other Request Bodies
rpy scripts (or, how to save yourself some typing)
Asynchronous Responses
Asynchronous Responses (via Deferred)
Interrupted Responses
Logging Errors
Access Logging
WSGI
HTTP Authentication
Session Basics
Storing Objects in the Session
Session Endings
Light Weight Templating With Resource Templates
Overview
Configuring Twisted Web
Using ResourceTemplate
Using the Twisted Web Client
Overview
The Agent
Conclusion
Glossary
Examples
twisted.web.client
XML-RPC
Virtual hosts and proxies
.rpys and ResourceTemplate
Miscellaneous
Twisted Words
Developer Guides
Overview of Twisted IM
Code flow
Using the Twisted IRC Client
Text formatting
Examples
Historical Documents
2003
Python Community Conference
Previously
Twisted
Docs
»
Twisted Conch
Edit on GitHub
Twisted Conch
¶
Developer guides
: documentation on using Twisted Conch to develop your own applications
Examples
: short code examples using Twisted Conch