Yury Selivanov | 3faaa88 | 2018-09-14 13:32:07 -0700 | [diff] [blame] | 1 | :mod:`asyncio` --- Asynchronous I/O |
| 2 | =================================== |
Guido van Rossum | 7a46564 | 2013-11-22 11:47:22 -0800 | [diff] [blame] | 3 | |
| 4 | .. module:: asyncio |
Yury Selivanov | 3faaa88 | 2018-09-14 13:32:07 -0700 | [diff] [blame] | 5 | :synopsis: Asynchronous I/O. |
Terry Jan Reedy | fa089b9 | 2016-06-11 15:02:54 -0400 | [diff] [blame] | 6 | |
Guido van Rossum | f8d0ff9 | 2013-11-22 16:53:25 -0800 | [diff] [blame] | 7 | -------------- |
Guido van Rossum | 7a46564 | 2013-11-22 11:47:22 -0800 | [diff] [blame] | 8 | |
Yury Selivanov | 6c73164 | 2018-09-14 14:57:39 -0700 | [diff] [blame^] | 9 | asyncio is a library to write **concurrent** code using |
| 10 | **async/await** syntax. |
Yury Selivanov | 3faaa88 | 2018-09-14 13:32:07 -0700 | [diff] [blame] | 11 | |
Yury Selivanov | 6c73164 | 2018-09-14 14:57:39 -0700 | [diff] [blame^] | 12 | asyncio is used as a foundation for multiple Python asynchronous |
| 13 | frameworks that provide high-performance network and web-servers, |
| 14 | database connection libraries, distributed task queues, etc. |
Antoine Pitrou | bba8682 | 2013-11-23 00:34:26 +0100 | [diff] [blame] | 15 | |
Yury Selivanov | 6c73164 | 2018-09-14 14:57:39 -0700 | [diff] [blame^] | 16 | asyncio is often a perfect fit for IO-bound and high-level |
| 17 | **structured** network code. |
Antoine Pitrou | bba8682 | 2013-11-23 00:34:26 +0100 | [diff] [blame] | 18 | |
Yury Selivanov | 6c73164 | 2018-09-14 14:57:39 -0700 | [diff] [blame^] | 19 | asyncio provides a set of **high-level** APIs to: |
Antoine Pitrou | bba8682 | 2013-11-23 00:34:26 +0100 | [diff] [blame] | 20 | |
Yury Selivanov | 6c73164 | 2018-09-14 14:57:39 -0700 | [diff] [blame^] | 21 | * :ref:`run Python coroutines <coroutine>` concurrently and |
| 22 | have full control over their execution; |
Antoine Pitrou | bba8682 | 2013-11-23 00:34:26 +0100 | [diff] [blame] | 23 | |
Yury Selivanov | 6c73164 | 2018-09-14 14:57:39 -0700 | [diff] [blame^] | 24 | * perform :ref:`network IO and IPC <asyncio-streams>`; |
Antoine Pitrou | bba8682 | 2013-11-23 00:34:26 +0100 | [diff] [blame] | 25 | |
Yury Selivanov | 6c73164 | 2018-09-14 14:57:39 -0700 | [diff] [blame^] | 26 | * control :ref:`subprocesses <asyncio-subprocess>`; |
Antoine Pitrou | bba8682 | 2013-11-23 00:34:26 +0100 | [diff] [blame] | 27 | |
Yury Selivanov | 6c73164 | 2018-09-14 14:57:39 -0700 | [diff] [blame^] | 28 | * distribute tasks via :ref:`queues <asyncio-queues>`; |
Antoine Pitrou | bba8682 | 2013-11-23 00:34:26 +0100 | [diff] [blame] | 29 | |
Yury Selivanov | 6c73164 | 2018-09-14 14:57:39 -0700 | [diff] [blame^] | 30 | * :ref:`synchronize <asyncio-sync>` concurrent code; |
Antoine Pitrou | bba8682 | 2013-11-23 00:34:26 +0100 | [diff] [blame] | 31 | |
Yury Selivanov | 6c73164 | 2018-09-14 14:57:39 -0700 | [diff] [blame^] | 32 | as well as **low-level** APIs for *library and framework developers* to: |
Guido van Rossum | f0f5d38 | 2013-11-22 15:45:02 -0800 | [diff] [blame] | 33 | |
Yury Selivanov | 6c73164 | 2018-09-14 14:57:39 -0700 | [diff] [blame^] | 34 | * create and manage :ref:`event loops <asyncio-event-loop>`, which |
| 35 | provide asynchronous APIs for networking, subprocesses, OS signals, |
| 36 | etc; |
Victor Stinner | 532c69a | 2015-02-25 14:23:51 +0100 | [diff] [blame] | 37 | |
Yury Selivanov | 6c73164 | 2018-09-14 14:57:39 -0700 | [diff] [blame^] | 38 | * implement efficient protocols using |
| 39 | :ref:`transports <asyncio-transports-protocols>`; |
| 40 | |
| 41 | * :ref:`bridge <asyncio-futures>` callback-based libraries and code |
| 42 | with async/await syntax. |
| 43 | |
| 44 | |
| 45 | Contents |
| 46 | -------- |
| 47 | |
| 48 | .. rubric:: High-level APIs |
Antoine Pitrou | bba8682 | 2013-11-23 00:34:26 +0100 | [diff] [blame] | 49 | |
Victor Stinner | ea3183f | 2013-12-03 01:08:00 +0100 | [diff] [blame] | 50 | .. toctree:: |
Yury Selivanov | 3faaa88 | 2018-09-14 13:32:07 -0700 | [diff] [blame] | 51 | :maxdepth: 1 |
| 52 | |
| 53 | asyncio-task.rst |
| 54 | asyncio-stream.rst |
| 55 | asyncio-sync.rst |
| 56 | asyncio-subprocess.rst |
| 57 | asyncio-queue.rst |
| 58 | asyncio-exceptions.rst |
| 59 | |
Yury Selivanov | 6c73164 | 2018-09-14 14:57:39 -0700 | [diff] [blame^] | 60 | .. rubric:: Low-level APIs |
Yury Selivanov | 3faaa88 | 2018-09-14 13:32:07 -0700 | [diff] [blame] | 61 | |
| 62 | .. toctree:: |
| 63 | :maxdepth: 1 |
Antoine Pitrou | bba8682 | 2013-11-23 00:34:26 +0100 | [diff] [blame] | 64 | |
Victor Stinner | ea3183f | 2013-12-03 01:08:00 +0100 | [diff] [blame] | 65 | asyncio-eventloop.rst |
Yury Selivanov | 3faaa88 | 2018-09-14 13:32:07 -0700 | [diff] [blame] | 66 | asyncio-future.rst |
| 67 | asyncio-protocol.rst |
Yury Selivanov | 7c7605f | 2018-09-11 09:54:40 -0700 | [diff] [blame] | 68 | asyncio-policy.rst |
| 69 | asyncio-platforms.rst |
Yury Selivanov | 3faaa88 | 2018-09-14 13:32:07 -0700 | [diff] [blame] | 70 | |
Yury Selivanov | 6c73164 | 2018-09-14 14:57:39 -0700 | [diff] [blame^] | 71 | .. rubric:: Guides and Tutorials |
Yury Selivanov | 3faaa88 | 2018-09-14 13:32:07 -0700 | [diff] [blame] | 72 | |
| 73 | .. toctree:: |
| 74 | :maxdepth: 1 |
| 75 | |
Victor Stinner | db39a0d | 2014-01-16 18:58:01 +0100 | [diff] [blame] | 76 | asyncio-dev.rst |
Yury Selivanov | 3faaa88 | 2018-09-14 13:32:07 -0700 | [diff] [blame] | 77 | |
Antoine Pitrou | bba8682 | 2013-11-23 00:34:26 +0100 | [diff] [blame] | 78 | |
Victor Stinner | 85a2be7 | 2013-12-03 15:04:36 +0100 | [diff] [blame] | 79 | .. seealso:: |
| 80 | |
Yury Selivanov | 3faaa88 | 2018-09-14 13:32:07 -0700 | [diff] [blame] | 81 | The :mod:`asyncio` module was proposed in :PEP:`3156`. |
| 82 | Since the acceptance of the PEP many new APIs were added and many |
| 83 | original APIs were altered. The PEP should be treated as a |
| 84 | historical document. |