Trio: 一个用于异步并发和 I/O 的友好 Python 库

Trio: a friendly Python library for async concurrency and I/O

Trio 项目的目标是创建一个 生产级宽松许可 的、原生支持 async/await 的 Python I/O 库。和所有异步库一样,它的主要目的是帮助您编写能够 同时执行多项任务 并实现 并行化 I/O 的程序。比如,一个需要并行抓取大量页面的网络爬虫、一个需要同时处理多个下载和 WebSocket 连接的 Web 服务器、一个监控多个子进程的进程管理器……诸如此类的需求。相比其他库,Trio 力求通过专注于 可用性正确性 来脱颖而出。并发编程很复杂,而我们试图使其 简单易用,以帮助开发者 正确地 完成任务。

Trio 从头开始设计,以充分利用 最新的 Python 特性,并从 多个来源 汲取灵感,特别是 Dave Beazley 的 Curio。最终的设计比传统库(如 asyncioTwisted)更简单直观,但同样功能完备。Trio 是我一直希望拥有的 Python I/O 库,它使构建 I/O 导向的程序更加轻松、减少错误,并且更有趣。也许您会有相同的感受。

这个项目仍然较年轻,带有一定的实验性质:整体设计稳固,现有功能经过全面测试和文档化,但您可能会遇到一些功能缺失或需要改进的地方。我们 鼓励您使用,但建议您 阅读并订阅 issue #1,以便在有任何影响兼容性的更改时获得通知并有机会提供反馈。

关键统计信息:

The Trio project's goal is to produce a production-quality, permissively licensed, async/await-native I/O library for Python. Like all async libraries, its main purpose is to help you write programs that do multiple things at the same time with parallelized I/O. A web spider that wants to fetch lots of pages in parallel, a web server that needs to juggle lots of downloads and websocket connections at the same time, a process supervisor monitoring multiple subprocesses... that sort of thing. Compared to other libraries, Trio attempts to distinguish itself with an obsessive focus on usability and correctness. Concurrency is complicated; we try to make it easy to get things right.

Trio was built from the ground up to take advantage of the latest Python features, and draws inspiration from many sources, in particular Dave Beazley's Curio. The resulting design is radically simpler than older competitors like asyncio and Twisted, yet just as capable. Trio is the Python I/O library I always wanted; I find it makes building I/O-oriented programs easier, less error-prone, and just plain more fun. Perhaps you'll find the same.

This project is young and still somewhat experimental: the overall design is solid and the existing features are fully tested and documented, but you may encounter missing functionality or rough edges. We do encourage you do use it, but you should read and subscribe to issue #1 to get warning and a chance to give feedback about any compatibility-breaking changes.

Vital statistics:

Trio 友好且全面的手册:

索引表

Indices and tables