# Tornado — Python Async Web Framework and Networking Library > Tornado is a Python web framework and asynchronous networking library originally developed at FriendFeed (acquired by Facebook). Non-blocking I/O, WebSockets, long polling, and thousands of simultaneous connections. One of the earliest async Python web frameworks. ## Install Save in your project root: ## Quick Use ```bash pip install tornado ``` ```python import tornado.ioloop import tornado.web import json class AssetsHandler(tornado.web.RequestHandler): def get(self): self.write(json.dumps([{"repo": "react", "stars": 230000}])) def post(self): data = json.loads(self.request.body) self.set_status(201) self.write(json.dumps(data)) class WebSocketHandler(tornado.websocket.WebSocketHandler): connections = set() def open(self): self.connections.add(self) def on_message(self, msg): for conn in self.connections: conn.write_message(msg) def on_close(self): self.connections.discard(self) app = tornado.web.Application([ (r"/api/assets", AssetsHandler), (r"/ws", WebSocketHandler), ]) if __name__ == "__main__": app.listen(8888) tornado.ioloop.IOLoop.current().start() ``` ## Intro Tornado is a Python web framework and asynchronous networking library originally developed at FriendFeed (acquired by Facebook in 2009). One of the earliest non-blocking I/O frameworks for Python, Tornado is designed for long-lived connections like WebSockets, long polling, and server-sent events. Used at Facebook, Quora, and other high-concurrency applications. - **Repo**: https://github.com/tornadoweb/tornado - **Stars**: 22K+ - **Language**: Python - **License**: Apache 2.0 ## What Tornado Does - **Non-blocking I/O** — event loop based - **Web framework** — routing, templates, auth, XSRF - **WebSocket** — native support - **HTTP client** — async HTTP requests - **Coroutines** — `async def` / `await` (modern) or `gen.coroutine` (legacy) - **asyncio compatible** — integrates with Python asyncio loop ## Comparison | Framework | Async Model | WebSocket | Era | |---|---|---|---| | Tornado | IOLoop (asyncio) | Built-in | 2009 | | FastAPI | ASGI (asyncio) | Via Starlette | 2018 | | Sanic | uvloop | Built-in | 2016 | | aiohttp | asyncio | Built-in | 2014 | ## 常见问题 FAQ **Q: 新项目还用 Tornado 吗?** A: 新项目推荐 FastAPI 或 Starlette。Tornado 主要维护老项目或需要自定义 IOLoop 的场景。 ## 来源与致谢 Sources - Docs: https://www.tornadoweb.org - GitHub: https://github.com/tornadoweb/tornado - License: Apache 2.0 --- Source: https://tokrepo.com/en/workflows/412ffd8f-3634-11f1-9bc6-00163e2b0d79 Author: AI Open Source