CharmingDays / AiohttpWrapper

A python wrapper for aiohttp to make it easier to reuse sessions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

aiohttp_wrapper

A python wrapper for aiohttp to make it easier to reuse sessions

There are 2 ways you can use this class

  • With the async with context manager
  • Without the `async with` context manager
  • async def with_context_manager(url:str):
        async with AioClientSession() as session:
            response = await session.get(url, should_read=True)
            print(await response.text())
    
    
    
    async def without_context_manager(url:str):
        session = AioClientSession()
        try:
            response = await session.get(url, should_read=True)
            print(await response.text())
        except Exception as e:
            # handle exception
            print(e)
        finally:
            await session.close()
    
    
    
    asyncio.run(without_context_manager('https://nekos.life/api/v2/img/neko'))

    About

    A python wrapper for aiohttp to make it easier to reuse sessions

    License:MIT License


    Languages

    Language:Python 100.0%