API Reference

Tornado

A Python web framework and asynchronous networking library with WebSockets and non-blocking IO.

Official Documentation ↗
CompatibilityThis documentation covers version v6.4. Check the official docs for the latest API surface.

Installation

pippip install tornado

Methods

Tornado centers on an IOLoop and RequestHandler classes, powering long-lived connections efficiently.

Key Features

  • Non-blocking IOLoop and coroutines
  • RequestHandler with async get and post
  • Native WebSocket support

Usage Notes

Pin a version and check the official docs for the API surface you depend on before upgrading.

Errors

The official API reference declares the following error types:

  • MissingArgumentError (请求参数缺失时由 get_argument/get_query_argument/get_body_argument 抛出) — official text: “If default is not provided, the argument is considered to be required, and we raise a MissingArgumentError if it is missing.” (source: https://www.tornadoweb.org/en/stable/web.html, fetched 2026-11-08T19:16:00+08:00)

Security

Official security statements captured from the package documentation:

  • write() 不把 list 转成 JSON,因存在跨站安全风险;JSON 输出应包裹在字典中 — “Note that lists are not converted to JSON because of a potential cross-site security vulnerability. All JSON output should be wrapped in a dictionary.” (source: https://www.tornadoweb.org/en/stable/web.html, fetched 2026-11-08T19:16:00+08:00)
  • RequestHandler 及其方法非线程安全,write()/finish()/flush() 只能在主线程调用 — “In general, methods on RequestHandler and elsewhere in Tornado are not thread-safe. In particular, methods such as write(), finish(), and flush() must only be called from the main thread.” (source: https://www.tornadoweb.org/en/stable/web.html, fetched 2026-11-08T19:16:00+08:00)

API reference evidence

Fetched from official sources on 2026-11-08T19:16:00+08:00 via WebFetch https://www.tornadoweb.org/en/stable/web.html(页面在 RequestHandler.send_error 段被截断,未含 Application 段);WebFetch https://www.tornadoweb.org/en/stable/ioloop.html;WebFetch https://www.tornadoweb.org/en/stable/webframework.html.

FAQ

Is Tornado still maintained?
Yes. It is a mature library, widely used for long-lived connections and WebSockets even as newer frameworks gain popularity.
How do I make an async HTTP call?
Use tornado.httpclient.AsyncHTTPClient with await; the blocking client must not be used inside the event loop.
How do I handle WebSockets?
Subclass WebSocketHandler and implement on_message, open, and on_close.