Welcome to AioContext

AioContext is a Python library to store context information within the asyncio.Task object:

import asyncio
import aiocontext

context = aiocontext.Context()

async def print_request():
    print("Request ID:", context.get('request_id', 'unknown'))

async def handle_request():
    context['request_id'] = 42
    await print_request()

if __name__ == '__main__':
    loop = asyncio.get_event_loop()


  • Support both asyncio and uvloop event loops.
  • Support custom loop task factories.
  • Manage several execution contexts.

If you can’t find the information you’re looking for, have a look at the index or try to find it using the search function: