Matt Makai - Python web dev & Twilio Developer Evangelist.

@mattmakai on Twitter & GitHub

Resources for WebSockets with Python

Before you learn node.js to handle WebSockets or any type of full-duplex client-server communication, check out some Python options first. In this post I'll lay out some of the resources that I found most helpful for getting started coding Python web applications that use WebSockets.

It's not necessary to have seen either talk but this page goes along with the San Francisco Python January 2015 meetup and Django District March 2015 meetup events.

Before diving in make sure you check out the WebSockets page on Full Stack Python. The page is new so it's a bit sparse at the moment but I'll continue filling it out throughout the rest of the month.

One more shamless plug: if you're going to PyCon this year make sure to check out the talks virtualenv for new Pythonista on Friday and Choose Your Own WSGI Deployment Adventure on Saturday.

Code for the WebSockets Talk

All code for the meetup live demo can be found on GitHub in the python-websockets-example repo.

The slides are also available but do not make a lot of sense without corresponding audio of the presentation.

General WebSocket resources

The below WebSocket resources aren't specific to Python but it's a good idea to get grounded in the technology itself first.

Evented networking frameworks

I recommend reading the awesome-python list of concurrency and networking libraries.

In the SF Python January 2015 and Django District March 2015 meetup groups I used gevent with Flask, Flask-SocketIO and SocketIO to handle WebSocket connections.

WebSockets with Python web frameworks

These resources are specific to using WebSockets with Python web frameworks like Django, Flask and Bottle and Klein. Each tutorial will show you step-by-step how to implement WebSockets with that framework.

WebSockets vs WebRTC Data vs SSE

There are multiple ways to accomplish server push and full duplex communication between web browsers and a server. The WebRTC Data Channel and Server-Sent Events (SSE) can provide similar functionality to WebSockets, although there are differences such as SSE not being able to push from client to server, only server to client. There is often confusion for how these technologies compare so it's a good idea to read a few of the posts below to survey the landscape.


« Back to blog