一句话:PyTrim 是端到端自动化删除 Python 项目未使用依赖的工具,并引入动态分析提升检测召回率。
依赖膨胀是 Python 项目长期面临的难题,会提高维护成本并带来安全风险。现有工具大多只能检测未使用的依赖,而跨源码与配置文件的删除仍需人工完成。本文提出 PyTrim,一个端到端系统,自动删除 Python 源文件中的未使用 import 以及 requirements.txt、setup.py 等配置文件中的冗余包声明。其模块化设计使其与依赖膨胀信息来源解耦,可集成任意检测工具;同时内置新颖的动态分析组件以提高依赖检测的召回率。作者在来自先前工作的 37 个已合并 pull request 的真值数据集上评估,PyTrim 复现人工修改的准确率达 98.3%。在实际应用中,PyTrim 在 971 个开源包上运行,识别并清理了其中 39 个包的膨胀依赖,并为每个案例提交了 pull request,已有 14 个被接受合并。工具已开源。
Dependency bloat is a persistent challenge in Python projects, which increases maintenance costs and security risks. While numerous tools exist for detecting unused dependencies in Python, removing these dependencies across the source code and configuration files of a project requires manual effort and expertise. To tackle this challenge we introduce PYTRIM, an end-to-end system to automate this process. PYTRIM eliminates unused imports and package declarations across a variety of file types, including Python source and configuration files such as requirements.txt and setup.py. PYTRIM’s modular design makes it agnostic to the source of dependency bloat information, enabling integration with any detection tool. Beyond its contribution when it comes to automation, PYTRIM also incorporates a novel dynamic analysis component that improves dependency detection recall. Our evaluation of PYTRIM’s end-to-end effectiveness on a ground-truth dataset of 37 merged pull requests from prior work, shows that PYTRIM achieves 98.3% accuracy in replicating human-made changes. To show its practical impact, we run PYTRIM on 971 open-source packages, identifying and trimming bloated dependencies in 39 of them. For each case, we submit a corresponding pull request, 14 of which have already been accepted and merged. PYTRIM is available as an open-source project, encouraging community contributions and further development.Video demonstration: https://youtu.be/LqTEdOUbJRICode repository: https://github.com/TrimTeam/PyTrim
@inproceedings{paperbot9352,
title = {PyTrim: A Practical Tool for Reducing Python Dependency Bloat},
author = {Konstantinos Karakatsanis and Georgios Alexopoulos and Ioannis Karyotakis and Foivos Timotheos Proestakis and Evangelos Talos and Panos Louridas and Dimitris Mitropoulos},
booktitle = {ASE},
year = {2025},
doi = {10.1109/ase63991.2025.00377}
}