PyMigTool: a tool for end-to-end Python library migration

📅 2025-10-09
📈 Citations: 0
Influential: 0
📄 PDF
🤖 AI Summary
Existing Python library migration tools are largely restricted to API-level mapping or specific library pairs, suffering from narrow coverage and low automation. This paper introduces the first end-to-end, general-purpose Python library migration framework, leveraging large language models (LLMs) as its core engine and integrating static analysis (to extract contextual dependencies) with dynamic analysis (to verify behavioral consistency), enabling fully automated code migration between functionally similar libraries. We propose a novel program-analysis-driven LLM post-processing optimization mechanism, significantly enhancing migration accuracy and robustness. Our command-line implementation is evaluated on 717 real-world projects: 32% achieve fully correct migrations, and in over 50% of projects, developers need to address fewer than 14% of residual changes—substantially reducing manual effort and error rates.

Technology Category

Application Category

📝 Abstract
Library migration is the process of replacing a library with a similar one in a software project. Manual library migration is time consuming and error prone, as it requires developers to understand the Application Programming Interfaces (API) of both libraries, map equivalent APIs, and perform the necessary code transformations. Due to the difficulty of the library migration process, most of the existing automated techniques and tooling stop at the API mapping stage or support a limited set of libraries and code transformations. In this paper, we develop an end-to-end solution that can automatically migrate code between any arbitrary pair of Python libraries that provide similar functionality. Due to the promising capabilities of Large Language Models (LLMs) in code generation and transformation, we use LLMs as the primary engine for migration. Before building the tool, we first study the capabilities of LLMs for library migration on a benchmark of 321 real-world library migrations. We find that LLMs can effectively perform library migration, but some post-processing steps can further improve the performance. Based on this, we develop PyMigTool, a command line application that combines the power of LLMs, static analysis, and dynamic analysis to provide accurate library migration. We evaluate PyMigTool on 717 real-world Python applications that are not from our benchmark. We find that PyMigTool can migrate 32% of the migrations with complete correctness. Of the remaining migrations, only 14% of the migration-related changes are left for developers to fix for more than half of the projects.
Problem

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

Automates Python library migration between arbitrary similar libraries
Uses LLMs with static and dynamic analysis for accurate transformations
Reduces manual effort in API mapping and code replacement tasks
Innovation

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

Uses LLMs for automated Python library migration
Combines static and dynamic analysis for accuracy
Provides end-to-end migration with minimal manual fixes
🔎 Similar Papers
No similar papers found.