asyncio.run is the usual entry point for an asyncio application. It creates a new event loop, runs one supplied coroutine until it completes, returns its result, cleans up remaining asynchronous work, and closes the loop. section 2.1.1
Running a coroutine
import asyncio async def coroutine_add_one(number: int) -> int: return number + 1 result = asyncio.run(coroutine_add_one(1)) print(result) # 2 Calling the coroutine directly would create a coroutine object without executing its body. asyncio.run places it on an event loop and executes it. section 2.1.1
Use asyncio.run as the boundary between synchronous startup code and asynchronous application work:
- Pass one main coroutine; have that coroutine create and coordinate the application's other coroutines and tasks. section 2.1.1
- Enable diagnostics with asyncio.run(coroutine(), debug=True) when investigating common asyncio problems. section 2.9.1 section 2.10
- Prefer it for ordinary loop setup, but manage the event loop directly when shutdown behavior or low-level scheduling requires custom control. section 2.8 section 3.6.2
Listing 2.3 Running a coroutine
import asyncio
async def coroutine_add_one(number: int) -> int:
return number + 1
result = asyncio.run(coroutine_add_one(1))
print(result)
A minimal runnable listing shows the complete pattern: define a coroutine, pass its invocation to asyncio.run, and consume the returned result. section 2.1.1

