{"id":2761,"library":"sanic","title":"Sanic","description":"Sanic is an asynchronous Python 3.10+ web server and web framework designed for high performance. It leverages Python's `async/await` syntax and optionally `uvloop` for blazing-fast I/O. Sanic is ASGI compliant, allowing flexible deployment, and offers a Flask-like API for rapid development. The project is actively maintained by the community, with a frequent release cadence, often monthly, following a YY.MM.PATCH versioning scheme. The current version is 25.12.0.","status":"active","version":"25.12.0","language":"en","source_language":"en","source_url":"http://github.com/sanic-org/sanic/","tags":["web-framework","async","asgi","performance","server","http"],"install":[{"cmd":"pip install sanic","lang":"bash","label":"Base Install"},{"cmd":"pip install \"sanic[ext]\"","lang":"bash","label":"Install with Sanic Extensions"}],"dependencies":[{"reason":"Used by default on Unix-like systems for increased performance; can be disabled with SANIC_NO_UVLOOP=true.","package":"uvloop","optional":true},{"reason":"Used by default for faster JSON processing; can be disabled with SANIC_NO_UJSON=true.","package":"ujson","optional":true},{"reason":"Core dependency for HTTP protocol parsing.","package":"httptools"},{"reason":"Core dependency for asynchronous file operations.","package":"aiofiles"},{"reason":"Core dependency for WebSocket functionality.","package":"websockets"}],"imports":[{"symbol":"Sanic","correct":"from sanic import Sanic"},{"note":"Sanic requires explicit response objects (e.g., `text()`, `json()`) unlike some other frameworks that implicitly convert return values.","wrong":"return \"Hello, world!\" or return {\"foo\": \"bar\"}","symbol":"Response types","correct":"from sanic.response import text, json"},{"note":"The `request` object is always passed as the first argument to route handlers, not accessed via a global context variable.","wrong":"from sanic.ctx import request","symbol":"Request","correct":"async def handler(request: Request):"}],"quickstart":{"code":"from sanic import Sanic\nfrom sanic.response import text\n\napp = Sanic(\"MyHelloWorldApp\")\n\n@app.get(\"/\")\nasync def hello_world(request):\n    return text(\"Hello, world.\")\n\nif __name__ == \"__main__\":\n    app.run(host=\"0.0.0.0\", port=8000, debug=True)","lang":"python","description":"This minimal Sanic application defines a single GET route at the root path ('/') that returns 'Hello, world.' It demonstrates app initialization, route decoration, explicit asynchronous handler definition, and using a Sanic response object. Run with `python your_app.py` or `sanic your_app:app --debug`."},"warnings":[{"fix":"Always wrap your return values in a `sanic.response` object, such as `text()`, `json()`, `html()`, or `file()`.","message":"Sanic requires explicit response objects (e.g., `text()`, `json()`). Unlike frameworks like Flask, returning raw strings or dictionaries from handlers is not supported and will result in errors, as Sanic aims to avoid implicit conversions for performance.","severity":"breaking","affected_versions":"All versions"},{"fix":"Transition to using `request.accept.match()` for content type negotiation.","message":"The functionality and parsing of `Request.accept` changed significantly. Relying on its equality operations may produce incorrect results. The `match()` method is now the preferred way to interact with `Request.accept`.","severity":"breaking","affected_versions":">=23.3.0"},{"fix":"Access and manipulate response cookies using object-oriented methods (e.g., `response.cookies['key']`, `del response.cookies['key']`) rather than dictionary-specific methods (like `.update()` or `.items()`).","message":"Response cookies are no longer dict-like objects. Direct dictionary methods (e.g., `cookie['key'] = value`) for `response.cookies` were removed.","severity":"breaking","affected_versions":">=24.3.0 (warnings started in 23.3.0)"},{"fix":"Ensure all routes have unique names. You can explicitly set a name using the `name` parameter in the `@app.route()` decorator or by ensuring function/class names are unique.","message":"Duplicate route names are no longer allowed. Registering multiple routes with the same name will raise a `sanic.exceptions.ServerError`.","severity":"breaking","affected_versions":">=23.3.0 (warnings started in 22.9.0)"},{"fix":"Migrate Gunicorn deployments to use Uvicorn for serving Sanic applications. Refer to Uvicorn's documentation for integration with Gunicorn.","message":"The `sanic.worker.GunicornWorker` class has been removed. Running Sanic with Gunicorn should now be done via `uvicorn` as an ASGI application.","severity":"deprecated","affected_versions":">=22.12.0 (removed in 23.3.0)"},{"fix":"On Windows, either set `SANIC_NO_UVLOOP=true` before installing/running, or use a Linux-based environment (e.g., WSL, Docker) for development and deployment.","message":"`uvloop` is Unix-specific. If `uvloop` is enabled (which is the default on supported platforms), Sanic applications may not run or perform optimally on Windows. You can explicitly disable `uvloop` via an environment variable.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-10T00:00:00.000Z","next_check":"2026-07-09T00:00:00.000Z"}