{"id":23033,"library":"aiohttp-asgi-connector","title":"aiohttp-asgi-connector","description":"Provides an aiohttp connector for running ASGI applications (e.g., Starlette, FastAPI) inside an aiohttp test harness or client without needing a live server. Current version 1.1.2, supports Python >=3.8, maintained on GitHub.","status":"active","version":"1.1.2","language":"python","source_language":"en","source_url":"https://github.com/kludex/aiohttp-asgi-connector","tags":["aiohttp","asgi","testing","connector","starlette","fastapi"],"install":[{"cmd":"pip install aiohttp-asgi-connector","lang":"bash","label":"PyPI install"}],"dependencies":[],"imports":[{"note":"ASGIConnector is not part of aiohttp's public API; must import from this library.","wrong":"from aiohttp import ASGIConnector","symbol":"ASGIConnector","correct":"from aiohttp_asgi_connector import ASGIConnector"}],"quickstart":{"code":"import asyncio\nimport aiohttp\nfrom aiohttp_asgi_connector import ASGIConnector\nfrom starlette.applications import Starlette\nfrom starlette.responses import PlainTextResponse\n\nasync def test():\n    app = Starlette()\n    async def homepage(request):\n        return PlainTextResponse('Hello, World!')\n    app.add_route('/', homepage)\n\n    connector = ASGIConnector(app)\n    async with aiohttp.ClientSession(connector=connector) as session:\n        async with session.get('http://testserver/') as resp:\n            print(await resp.text())\n\nasyncio.run(test())","lang":"python","description":"Creates an aiohttp connector that wraps an ASGI app for in-process testing."},"warnings":[{"fix":"connector = ASGIConnector(app, lifespan=False)","message":"The ASGI app must have a lifespan handler. If the app does not implement lifespan events (startup/shutdown), you may need to pass 'lifespan=False' to ASGIConnector.","severity":"gotcha","affected_versions":"all"},{"fix":"Override the Host header in your aiohttp request or configure the ASGI app accordingly.","message":"The connector automatically adds a 'testserver' host header. If your ASGI app validates the Host header, ensure it matches 'testserver' or disable host checking.","severity":"gotcha","affected_versions":"all"},{"fix":"Update install and import to 'aiohttp-asgi-connector' and 'from aiohttp_asgi_connector import ASGIConnector'.","message":"Older versions required importing from 'aiohttp_asgi' (note: singular 'asgi'). The package name changed to 'aiohttp-asgi-connector' and import path to 'aiohttp_asgi_connector'.","severity":"deprecated","affected_versions":"<1.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Install aiohttp-asgi-connector and use: from aiohttp_asgi_connector import ASGIConnector","cause":"Attempting to import ASGIConnector from the aiohttp package, which doesn't expose it.","error":"ImportError: cannot import name 'ASGIConnector' from 'aiohttp'"},{"fix":"Pass lifespan=False to ASGIConnector: connector = ASGIConnector(app, lifespan=False)","cause":"ASGI app does not have a lifespan handler or is not properly handling lifespan messages. Often happens with simple apps that lack lifespan.","error":"AttributeError: 'NoneType' object has no attribute 'send'"},{"fix":"Use asyncio.run() or an async test framework like pytest-asyncio to manage the loop.","cause":"Running an async test outside an event loop or incorrectly closing the loop before the session finishes.","error":"RuntimeError: Event loop is closed"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}