blob: c1b04086c35f08778e02e3ef4cbf447dc0ded979 [file] [log] [blame]
Yury Selivanov3faaa882018-09-14 13:32:07 -07001:mod:`asyncio` --- Asynchronous I/O
2===================================
Guido van Rossum7a465642013-11-22 11:47:22 -08003
4.. module:: asyncio
Yury Selivanov3faaa882018-09-14 13:32:07 -07005 :synopsis: Asynchronous I/O.
Terry Jan Reedyfa089b92016-06-11 15:02:54 -04006
Guido van Rossumf8d0ff92013-11-22 16:53:25 -08007--------------
Guido van Rossum7a465642013-11-22 11:47:22 -08008
Yury Selivanov6c731642018-09-14 14:57:39 -07009asyncio is a library to write **concurrent** code using
10**async/await** syntax.
Yury Selivanov3faaa882018-09-14 13:32:07 -070011
Yury Selivanov6c731642018-09-14 14:57:39 -070012asyncio is used as a foundation for multiple Python asynchronous
13frameworks that provide high-performance network and web-servers,
14database connection libraries, distributed task queues, etc.
Antoine Pitroubba86822013-11-23 00:34:26 +010015
Yury Selivanov6c731642018-09-14 14:57:39 -070016asyncio is often a perfect fit for IO-bound and high-level
17**structured** network code.
Antoine Pitroubba86822013-11-23 00:34:26 +010018
Yury Selivanov6c731642018-09-14 14:57:39 -070019asyncio provides a set of **high-level** APIs to:
Antoine Pitroubba86822013-11-23 00:34:26 +010020
Yury Selivanov6c731642018-09-14 14:57:39 -070021* :ref:`run Python coroutines <coroutine>` concurrently and
22 have full control over their execution;
Antoine Pitroubba86822013-11-23 00:34:26 +010023
Yury Selivanov6c731642018-09-14 14:57:39 -070024* perform :ref:`network IO and IPC <asyncio-streams>`;
Antoine Pitroubba86822013-11-23 00:34:26 +010025
Yury Selivanov6c731642018-09-14 14:57:39 -070026* control :ref:`subprocesses <asyncio-subprocess>`;
Antoine Pitroubba86822013-11-23 00:34:26 +010027
Yury Selivanov6c731642018-09-14 14:57:39 -070028* distribute tasks via :ref:`queues <asyncio-queues>`;
Antoine Pitroubba86822013-11-23 00:34:26 +010029
Yury Selivanov6c731642018-09-14 14:57:39 -070030* :ref:`synchronize <asyncio-sync>` concurrent code;
Antoine Pitroubba86822013-11-23 00:34:26 +010031
Yury Selivanov6c731642018-09-14 14:57:39 -070032as well as **low-level** APIs for *library and framework developers* to:
Guido van Rossumf0f5d382013-11-22 15:45:02 -080033
Yury Selivanov6c731642018-09-14 14:57:39 -070034* create and manage :ref:`event loops <asyncio-event-loop>`, which
35 provide asynchronous APIs for networking, subprocesses, OS signals,
36 etc;
Victor Stinner532c69a2015-02-25 14:23:51 +010037
Yury Selivanov6c731642018-09-14 14:57:39 -070038* 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
45Contents
46--------
47
48.. rubric:: High-level APIs
Antoine Pitroubba86822013-11-23 00:34:26 +010049
Victor Stinnerea3183f2013-12-03 01:08:00 +010050.. toctree::
Yury Selivanov3faaa882018-09-14 13:32:07 -070051 :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 Selivanov6c731642018-09-14 14:57:39 -070060.. rubric:: Low-level APIs
Yury Selivanov3faaa882018-09-14 13:32:07 -070061
62.. toctree::
63 :maxdepth: 1
Antoine Pitroubba86822013-11-23 00:34:26 +010064
Victor Stinnerea3183f2013-12-03 01:08:00 +010065 asyncio-eventloop.rst
Yury Selivanov3faaa882018-09-14 13:32:07 -070066 asyncio-future.rst
67 asyncio-protocol.rst
Yury Selivanov7c7605f2018-09-11 09:54:40 -070068 asyncio-policy.rst
69 asyncio-platforms.rst
Yury Selivanov3faaa882018-09-14 13:32:07 -070070
Yury Selivanov6c731642018-09-14 14:57:39 -070071.. rubric:: Guides and Tutorials
Yury Selivanov3faaa882018-09-14 13:32:07 -070072
73.. toctree::
74 :maxdepth: 1
75
Victor Stinnerdb39a0d2014-01-16 18:58:01 +010076 asyncio-dev.rst
Yury Selivanov3faaa882018-09-14 13:32:07 -070077
Antoine Pitroubba86822013-11-23 00:34:26 +010078
Victor Stinner85a2be72013-12-03 15:04:36 +010079.. seealso::
80
Yury Selivanov3faaa882018-09-14 13:32:07 -070081 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.