别小看 wrapture

Simon Willison's Blog 工具

摘要

文章强调了 Python 包 'wrapture' 作为猴子补丁、测试和可观测性不可或缺的工具,尽管仍处于 alpha 阶段,但教程和潜力都在增长。

暂无内容
查看原文
查看缓存全文

缓存时间: 2026/09/11 14:17

# 别忽视 wrapture 来源:https://simonwillison.net/2026/Sep/11/wrapture/ 2026年9月11日 Graham Dumpleton 新推出的猴子补丁包 wrapture (https://wrapture.readthedocs.io/) 正迅速成为 Python 开发者不可或缺的工具。我不确定为何至今关注的人这么少! 自8月31日首次发布 (https://simonwillison.net/2026/Aug/31/introducing-wrapture/) 以来,Graham几乎每天都在发布相关教程。以下是他迄今为止发布的全部内容: - wrapture 介绍 (https://grahamdumpleton.me/posts/2026/08/introducing-wrapture/) - 一个全新的猴子补丁库,同时服务于测试和可观测性(想象 New Relic 风格的追踪)。 - 使用 wrapture 进行单元测试 (https://grahamdumpleton.me/posts/2026/09/unit-testing-with-wrapture/) - 如何用它实现与 `unittest.mock` 类似的功能。 - 使用 wrapture 录制调用 (https://grahamdumpleton.me/posts/2026/09/recording-calls-with-wrapture/) - 将方法调用录制为时间线,并将其作为树状图进行处理和展示。 - wrapture 中的分阶段行为 (https://grahamdumpleton.me/posts/2026/09/phased-behaviour-in-wrapture/) - 让补丁方法在多次调用中改变行为。 - wrapture 的超越可调用对象 (https://grahamdumpleton.me/posts/2026/09/beyond-callables-in-wrapture/) - 对属性、字典、生成器进行猴子补丁。 - 使用 wrapture 进行实时追踪 (https://grahamdumpleton.me/posts/2026/09/live-tracing-with-wrapture/) - 追踪一个正在运行的应用程序,以精确了解其工作方式。 - 使用 wrapture 进行零代码追踪 (https://grahamdumpleton.me/posts/2026/09/zero-code-tracing-with-wrapture/) - 通过单独的 TOML 文件配置追踪,完全无需修改 Python 代码。 - 使用 wrapture 追踪 Flask (https://grahamdumpleton.me/posts/2026/09/tracing-flask-with-wrapture/) - 使用独立的 wrapture-instrumentation (https://github.com/GrahamDumpleton/wrapture-instrumentation) 包来检测 Flask 应用程序。该包还提供了对 `aiohttp.client`、`aiohttp.web`、`django`、`fastapi`、`flask`、`grpc`、`http.client`、`httpx`、`jinja2`、`requests`、`sqlalchemy`、`sqlite3`、`starlette`、`urllib.request`、`urllib3`、`uvicorn`、`werkzeug.serving`、`wsgiref.simple_server`、`xmlrpc.client`、`xmlrpc.server` 的检测支持。 - 使用 wrapture 发现慢代码 (https://grahamdumpleton.me/posts/2026/09/finding-slow-code-with-wrapture/) - wrapture 用于记录计时信息(单次和多次调用聚合)的工具。 - wrapture 中的 OpenTelemetry 导出 (https://grahamdumpleton.me/posts/2026/09/opentelemetry-export-in-wrapture/) - 将追踪数据导出到 OpenTelemetry。 Graham 还为 wrapture 提供了一套交互式研讨会 (https://github.com/GrahamDumpleton/wrapture-workshops),以 JupyterLab 笔记本的形式实现。 Wrapture 仍处于 alpha 阶段,但已非常实用——尤其鉴于你可以通过 TOML 文件配置并试用它,完全无需修改任何 Python 代码。 这感觉就像一把瑞士军刀式的工具包,一旦掌握,将在未来数年内持续为解决各类问题提供价值。

相似文章

介绍 wrapture

Simon Willison's Blog

介绍 wrapture,一个全新的 Python 库,用于 monkeypatching、测试和追踪,支持 OpenTelemetry,并且其开发完全由 AI 辅助。

使用 Wrapture 发现慢代码

Hacker News Top

本文展示了如何使用 Wrapture 这一开发工具,通过插桩和时间线分析来识别 Flask 应用程序中的慢代码,从而精确定位性能瓶颈。