aiohttp-swagger
raw JSON → 1.0.16 verified Mon Apr 27 auth: no python maintenance
Swagger API Documentation builder for aiohttp server. Version 1.0.16 (last release 2020). No recent updates; likely in maintenance mode.
pip install aiohttp-swagger Common errors
error ImportError: cannot import name 'setup_swagger' from 'aiohttp_swagger' ↓
cause Installed version < 1.0.0 or wrong import path
fix
Upgrade to latest: pip install --upgrade aiohttp-swagger
error TypeError: setup_swagger() got an unexpected keyword argument 'swagger_url' ↓
cause Older version of library does not support swagger_url parameter
fix
Use 'url' instead: setup_swagger(app, url='/api/v1/doc')
error AttributeError: module 'aiohttp_swagger' has no attribute 'swagger' ↓
cause Misunderstanding the import; 'swagger' is a decorator, not a function
fix
Use: from aiohttp_swagger import swagger as swagger_decorator
Warnings
breaking aiohttp-swagger may not work with aiohttp >= 4.x due to API changes. ↓
fix Pin aiohttp<4 or use alternative like aiohttp-swagger3 or aiohttp-swagger-ui
deprecated Project has not been updated since 2020. Consider using more actively maintained alternatives. ↓
fix Switch to aiohttp-swagger3 or aiohttp-swagger-ui
gotcha setup_swagger expects aiohttp.Application instance. Passing a sub-app may cause issues. ↓
fix Ensure you pass the main app object, not a nested app.
Imports
- setup_swagger wrong
from aiohttp_swagger import swaggercorrectfrom aiohttp_swagger import setup_swagger - swagger
from aiohttp_swagger import swagger - swagger_path
from aiohttp_swagger import swagger_path
Quickstart
from aiohttp import web
from aiohttp_swagger import setup_swagger
async def handler(request):
return web.json_response({"hello": "world"})
app = web.Application()
app.router.add_get('/hello', handler)
setup_swagger(app, swagger_url="/api/v1/doc")
web.run_app(app, host='0.0.0.0', port=8080)