Generated by GPT-5-mini| Trio (library) | |
|---|---|
| Name | Trio |
| Developer | Quansight; contributors including developers from Python (programming language), Mozilla, Dropbox (company), Microsoft |
| Released | 2016 |
| Programming language | Python (programming language) |
| Operating system | Unix-like; Microsoft Windows; macOS |
| Platform | CPython |
| Repository | GitHub |
| License | MIT License |
Trio (library)
Trio is an asynchronous I/O library for Python (programming language) that provides structured concurrency primitives for writing concurrent programs. Influenced by research and implementations in Go (programming language), Erlang, and Rust (programming language), Trio emphasizes correctness, cancellation safety, and simple mental models for developers coming from projects like asyncio and Twisted. Trio is used in software projects associated with organizations such as Mozilla, Dropbox (company), and academic groups at MIT and Harvard University.
Trio offers an alternative to asyncio and Twisted by providing a minimal core API built around nurseries, tasks, and cancellation scopes inspired by structured concurrency proposals from Martin Sústrik, Rob Pike, and researchers at Carnegie Mellon University. The library exposes async/await-compatible primitives that integrate with the CPython runtime and the PEP 3156 async architecture debates. Trio's design goals include deterministic cancellation behavior, clear error propagation, and composability, addressing concurrency pitfalls discussed in work from XKCD authors and systems researchers at ETH Zurich and University of Cambridge.
Trio's architecture centers on a single-threaded event loop abstraction called the "Trio loop," which orchestrates cooperative multitasking using async functions and nurseries. The nursery abstraction lets developers spawn child tasks with lexical scope, mirroring proposals from Tony Hoare's work and later structured concurrency research at INRIA and Microsoft Research. Trio implements cancellation scopes that behave predictably under exception handling, a concept aligned with resource-safe patterns in Rust (programming language) and transactional models explored at Stanford University. The library integrates drivers for operating system primitives like epoll, kqueue, and IOCP to run on Linux, FreeBSD, and Windows platforms while interoperating with low-level libraries such as libuv and system APIs used by Nginx and Apache HTTP Server.
Trio provides async/await coroutines, nurseries, events, locks, and channels with a small surface area inspired by API work at Google and language proposals for Kotlin coroutines. The nursery pattern enforces a structured lifecycle similar to scoped threads in C++ libraries and supervision trees in Erlang. The API contains primitives like open_memory_channel, CancelScope, and SocketStream that mirror abstractions from networking frameworks used by Twisted and aiohttp. Trio's error handling model ensures that exceptions from child tasks propagate to parents deterministically, reflecting philosophies advocated in literature from ACM conferences and papers from USENIX. Adapters such as trio-asyncio and asyncclick enable interop with asyncio libraries and CLI tooling influenced by Click (software).
Benchmarking Trio involves comparing event loop throughput, latency, and task-switch cost against asyncio, Twisted, and native-threaded approaches found in Java (programming language) runtimes and Go (programming language). Independent benchmarks by contributors from Quansight and reports from developers at Dropbox (company) show Trio performing competitively on I/O-bound workloads, with lower latency in cancellation-heavy scenarios than traditional callback-based frameworks like Node.js and libuv-based servers. Microbenchmarks published in community discussions at PyCon and EuroPython indicate that while raw throughput can favor highly-optimized event loops in CPython extensions, Trio's predictable behavior and debugging ergonomics yield advantages in production systems used by Mozilla and research prototypes at Imperial College London.
Trio is used for networking stacks, protocol implementations, and I/O-bound services where correct cancellation and supervision are critical. Projects in the ecosystem include TLS stacks, HTTP client/server libraries, and database connection pools developed by teams at Matrix (protocol), Canonical (company), and independent developers featured at PyCon US. Research groups at University of Oxford and startups in Silicon Valley have adopted Trio for rapid prototyping of distributed systems and secure networking tools. Integration adapters allow Trio code to run alongside asyncio-based web frameworks and testing tools from pytest and CI systems used by GitHub.
Trio originated from open-source work led by developers associated with Quansight and community contributors active on GitHub and the Python Software Foundation mailing lists. The project evolved through design discussions inspired by academic papers from PLDI and OOPSLA proceedings and through community-driven issues and pull requests influenced by users from Red Hat, Microsoft, and independent researchers at University of California, Berkeley. Trio's maintainers collaborate via GitHub, discuss designs on Python Enhancement Proposal fora, and present implementations at conferences such as PyCon, EuroPython, and FOSDEM.
Trio is distributed under the MIT License, facilitating use in commercial and academic projects similar to licensing choices by NumPy and Pandas. It targets modern versions of CPython and interops with ecosystem tools like setuptools and pip while offering adapters to bridge with asyncio-centric libraries. Compatibility considerations include integration with native extensions written for CPython and coordination with operating system event facilities on Linux, macOS, and Windows.
Category:Python (programming language) libraries