Basic async function and await pattern.
Section: Getting Started
Define and await a coroutine
python
python
import asyncio
async def fetch_name():
await asyncio.sleep(0.2)
return "jon"
async def main():
name = await fetch_name()
print(name)
asyncio.run(main())Explanation
An `async def` function returns a coroutine object. Use `await` only inside another async function.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Getting Started
Run an async entrypoint
Execute a top-level coroutine and manage the event loop automatically.
Use asyncio.Runner for multiple async calls
Reuse a managed loop for multiple top-level async calls.
Get the running loop and monotonic time
Use the loop clock for scheduling and deadlines.