PyTrim: A Practical Tool for Reducing Python Dependency Bloat

📅 2025-10-01
📈 Citations: 0
Influential: 0
📄 PDF
🤖 AI Summary
Python projects commonly suffer from dependency bloat, increasing maintenance overhead and security risks. Existing tools can only detect unused dependencies but require manual intervention for removal. This paper introduces DepClean, an end-to-end automated dependency minimization framework. It features a modular architecture compatible with diverse static and dynamic analysis tools, and innovatively integrates static parsing—supporting `.py`, `requirements.txt`, `setup.py`, and related formats—with lightweight dynamic analysis, significantly improving recall. Evaluated on 37 real-world pull requests, DepClean achieves 98.3% precision. Applied to 971 open-source packages, it identified 39 redundant dependencies; 39 corresponding PRs were submitted, with 6 already merged. To the best of our knowledge, this is the first work enabling fully automated identification and removal of unused dependencies across both configuration files and source code.

Technology Category

Application Category

📝 Abstract
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, 6 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/LqTEdOUbJRI Code repository: https://github.com/TrimTeam/PyTrim
Problem

Research questions and friction points this paper is trying to address.

Automates removal of unused Python dependencies across files
Reduces maintenance costs and security risks from dependency bloat
Improves dependency detection recall through dynamic analysis
Innovation

Methods, ideas, or system contributions that make the work stand out.

Automates removal of unused dependencies across files
Uses modular design for integration with detection tools
Incorporates dynamic analysis to improve detection recall
🔎 Similar Papers
No similar papers found.
K
Konstantinos Karakatsanis
Athens University of Economics and Business
Georgios Alexopoulos
Georgios Alexopoulos
PhD candidate, National and Kapodistrian University of Athens
Software EngineeringComputer Security
I
Ioannis Karyotakis
Athens University of Economics and Business
F
Foivos Timotheos Proestakis
Athens University of Economics and Business
E
Evangelos Talos
Athens University of Economics and Business
P
Panos Louridas
Athens University of Economics and Business
Dimitris Mitropoulos
Dimitris Mitropoulos
Associate Professor, National and Kapodistrian University of Athens
Software EngineeringComputer Security