Debian Codegraph @

README.rst

raw
1 Crochet: Use Twisted anywhere!
2 ==============================
3
4 Crochet is an MIT-licensed library that makes it easier to use Twisted from
5 regular blocking code. Some use cases include:
6
7 * Easily use Twisted from a blocking framework like Django or Flask.
8 * Write a library that provides a blocking API, but uses Twisted for its
9 implementation.
10 * Port blocking code to Twisted more easily, by keeping a backwards
11 compatibility layer.
12 * Allow normal Twisted programs that use threads to interact with Twisted more
13 cleanly from their threaded parts. For example, this can be useful when using
14 Twisted as a `WSGI container`_.
15
16 .. _WSGI container: https://twistedmatrix.com/documents/current/web/howto/web-in-60/wsgi.html
17
18 Crochet is maintained by Itamar Turner-Trauring.
19
20 **Note:** Crochet development is pretty slow these days because mostly it **Just Works**. PyPI shows about 30,000 downloads a month, so existing users seem happy: https://pypistats.org/packages/crochet
21
22 You can install Crochet by running::
23
24 $ pip install crochet
25
26 Downloads are available on `PyPI`_.
27
28 Documentation can be found on `Read The Docs`_.
29
30 Bugs and feature requests should be filed at the project `Github page`_.
31
32 .. _Read the Docs: https://crochet.readthedocs.org/
33 .. _Github page: https://github.com/itamarst/crochet/
34 .. _PyPI: https://pypi.python.org/pypi/crochet
35
36
37 API and features
38 ================
39
40 Crochet supports Python 3.8, 3.9, 3.10, and 3.11 as well as PyPy3.
41
42 Crochet provides the following basic APIs:
43
44 * Allow blocking code to call into Twisted and block until results are available
45 or a timeout is hit, using the ``crochet.wait_for`` decorator.
46 * A lower-level API (``crochet.run_in_reactor``) allows blocking code to run
47 code "in the background" in the Twisted thread, with the ability to repeatedly
48 check if it's done.
49
50 Crochet will do the following on your behalf in order to enable these APIs:
51
52 * Transparently start Twisted's reactor in a thread it manages.
53 * Shut down the reactor automatically when the process' main thread finishes.
54 * Hook up Twisted's log system to the Python standard library ``logging``
55 framework. Unlike Twisted's built-in ``logging`` bridge, this includes
56 support for blocking `Handler` instances.