Crochet: Use Twisted Anywhere!

Crochet is an MIT-licensed library that makes it easier for blocking and threaded applications like Flask or Django to use the Twisted networking framework.

Here’s an example of a program using Crochet:

Download a web page in a blocking manner.

from __future__ import print_function

import sys

from twisted.web.client import getPage
from crochet import setup, wait_for_reactor

def download_page(url):
    return getPage(url)

# download_page() now behaves like a normal blocking function:

Run on the command line:

$ python
<!doctype html><html itemscope="itemscope" ... etc. ...

Notice that you get a completely blocking interface to Twisted and do not need to run the Twisted reactor, the event loop, yourself.