Sanic + aiohttp

stare = Sanic(__name__)
stare.blueprint(
    Blueprint.group(
        asa_campaign,
        asa_adgroup,
        asa_keyword,
        asa_creative_sets,
        url_prefix='/stare/api/',
        version=1)
)
stare.config.REQUEST_TIMEOUT = 120
stare.config.RESPONSE_TIMEOUT = 120
stare.config.ACCESS_LOG = False

@stare.listener('before_server_start')
async def initialize(app, loop):
    aiohttp_session = aiohttp.ClientSession()


How can the “aiohttp_session” declared in the main route be used in the registered route?

@stare.listener('before_server_start')
async def initialize(app, loop):
    aiohttp_session = aiohttp.ClientSession()
    for _ in stare.blueprints.values():
        _.aiohttp_session = aiohttp_session

You should really use the ctx objects. There is one on Blueprints, but the one typically used for this type of operation is on the application instance: