Previous proposalFalcon: Bare-metal web API framework for Python
Submitted by Jaysinh shukla (@jaysinhp) on Tuesday, 19 February 2019
Technical level: Intermediate Status: Submitted
Twisted is a framework for writing event-driven applications in Python. Event-driven is a well-recommended programming paradigm for writing high performance networking applications, GUI applications or device drivers. The framework is more than a decade old and has a large community base. I am proposing an entry-level workshop to share my expertise with the community.
Duration: 180 minutes excluding breaks and question answers.
- What is an event-driven programming paradigm?
- Important components of the framework
- Protocol factories
- Demonstration of writing tests for a real-world application
- Guidelines on writing tests
- Deployment guidelines
- Seeking help from the community
- Mailing list
I will explain the gist of event-driven programming paradigm. I will do a small comparison of this with the existing paradigm. Event-loops are the core of event-driven programming. I will explain how the loop communicates for scheduling tasks.
Twisted is largely platform independent, but also includes platform-specific functionalities. Installation of Twisted is as simple as installing any Python package.
Components of the Framework:
The reactor is an event-loop which drives the application.
Callbacks are a fundamental part of event-driven programming and are the way that the reactor indicates to an application that an event has arrived. There is two type of callbacks. One is when the event has succeeded and the other is when the event has failed. It is quite common to tangle the logic between success and failure callbacks. Twisted provides a great solution to write these callbacks by giving deferred interfaces.
Transport is a collection of various transport classes. It provides an API to transfer bytes to another end of the socket.
The protocol describes how to react to events. Protocol factory is responsible for producing an instance of the protocol. All the configuration information are preserved in a protocol factories.
Testing Twisted code is tricky. I will demonstrate mocking response objects and show how to avoid polluting an event loop. I will be focusing on utilities of “twisted.trial” module.
Deploying a Twisted-based application is like deploying any other Python application. I will point out various ways to deploy and maintain a Twisted-based application.
Seeking help from the community
I will conclude this workshop by sharing resources to get involved with the community and continue to learn.
A laptop with Python 3 and a will to learn :)