Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python.announce > #2107

Crochet 1.5.0: Use Twisted in Django, Flask, or anywhere else

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Itamar Turner-Trauring <itamar@itamarst.org>
Newsgroups comp.lang.python.announce
Subject Crochet 1.5.0: Use Twisted in Django, Flask, or anywhere else
Date Wed, 13 Apr 2016 16:18:22 -0400
Lines 45
Approved python-announce-list@python.org
Message-ID <mailman.87.1460581033.15650.python-announce-list@python.org> (permalink)
References <570EA98E.6010401@itamarst.org>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding 7bit
X-Trace news.uni-berlin.de Or0zcB8Fk6XDfWYn4dnsgQmUbQG+r0ul71/BSprtju6w==
Return-Path <itamar@itamarst.org>
X-Original-To python-announce-list@python.org
Delivered-To python-announce-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'subject:Django': 0.03; 'sys': 0.05; '__name__': 0.07; 'apis': 0.07; 'api': 0.09; '"""use': 0.09; '__future__': 0.09; 'django,': 0.09; 'hiding': 0.09; 'python': 0.10; 'def': 0.13; '(but': 0.15; "'__main__':": 0.16; 'manner,': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'result:': 0.16; 'threads': 0.16; 'twisted': 0.16; 'library': 0.20; 'versions': 0.20; 'to:2**1': 0.21; 'disable': 0.22; 'setup,': 0.22; '(or': 0.23; 'import': 0.24; 'example': 0.26; 'supported': 0.27; 'blocking': 0.29; 'code': 0.30; 'older': 0.32; 'lets': 0.33; 'skip:d 20': 0.34; 'that,': 0.34; 'url:org': 0.36; 'received:10.20': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'client': 0.37; 'starting': 0.37; 'application': 0.39; 'easily': 0.39; 'to:addr:python.org': 0.40; 'still': 0.40; 'your': 0.60; 'provide': 0.61; 'providing': 0.62; 'more': 0.63; 'wish': 0.71; 'power': 0.72; 'subject:else': 0.84; 'url:readthedocs': 0.84; 'exposing': 0.91; 'officially': 0.91
X-Virus-Scanned amavisd-new at kolabnow.com
X-Spam-Flag NO
X-Spam-Score -2.899
X-Spam-Level
X-Spam-Status No, score=-2.899 tagged_above=-10 required=6.31 tests=[ALL_TRUSTED=-1, BAYES_00=-1.9, HTML_MESSAGE=0.001] autolearn=ham
X-Mailman-Approved-At Wed, 13 Apr 2016 16:57:13 -0400
X-Content-Filtered-By Mailman/MimeDel 2.1.21
X-BeenThere python-announce-list@python.org
X-Mailman-Version 2.1.21
Precedence list
List-Id Announcement-only list for the Python programming language <python-announce-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-announce-list>, <mailto:python-announce-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-announce-list/>
List-Post <mailto:python-announce-list@python.org>
List-Help <mailto:python-announce-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-announce-list>, <mailto:python-announce-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <570EA98E.6010401@itamarst.org>
Xref csiph.com comp.lang.python.announce:2107

Show key headers only | View raw


Do you wish you could:

  * Use the power of Twisted's asynchronous networking in Django, Flask,
    or other threaded applications?
  * Provide a blocking API powered by Twisted underneath, without
    exposing it to the caller?
  * Write a library that provides APIs both for Twisted and non-Twisted
    applications?
  * Use threads more easily inside Twisted applications?

Crochet lets you do all that, and more, by hiding and automatically 
starting the Twisted reactor and providing a blocking API for calling 
into Twisted. If you need to use your library from a normal Twisted 
application you can disable the auto-start functionality. Here's an 
example of using Twisted in a blocking manner:

from __future__ import print_function
from twisted.names import client
from crochet import setup, wait_for
setup()

@wait_for(timeout=5.0)
def gethostbyname(name):
      """Use the Twisted DNS library."""
      d = client.lookupAddress(name)
      d.addCallback(lambda result: result[0][0].payload.dottedQuad())
      return d

if __name__ == '__main__':
      # Application code using the public API - notice it works in a normal
      # blocking manner, with no event loop visible:
      import sys
      name = sys.argv[1]
      ip = gethostbyname(name)
      print(name, "->", ip)

New in 1.5.0 is official Python 3.5 support; Python 2.6, 3.3 and older 
versions of Twisted are no longer officially supported (but are likely 
to still work).

If you need help using Crochet (or just general Twisted or Python help) 
I am currently available for short-term consulting. You can read the 
documentation at https://crochet.readthedocs.org/.

--Itamar Turner-Trauring

Back to comp.lang.python.announce | Previous | Next | Find similar | Unroll thread


Thread

Crochet 1.5.0: Use Twisted in Django, Flask, or anywhere else Itamar Turner-Trauring <itamar@itamarst.org> - 2016-04-13 16:18 -0400

csiph-web