Pig: Leveraging Large Language Models for Python Library Migrations
Open Access
- 30 June 2026
- journal article
- Published by Association for Computing Machinery (ACM) in Proceedings of the ACM on Software Engineering
- Vol. 3 (FSE) , 967-988
Abstract
We present Pig, a novel approach to automating Python library migration by leveraging large language models (LLMs). Library migration is an increasingly common task in modern Python development, yet it remains tedious and error-prone due to the lack of general solutions that can handle diverse libraries without relying on documentation or code examples. To address this challenge, Pig employs a four-step pipeline that effectively harnesses the capabilities of LLMs. First, Pig decomposes the migration task into smaller units by performing API-level slicing, allowing the LLM to focus on minimal, relevant context. Second, it guides LLMs using prompts informed by common failure patterns in naive LLM-based migrations and plausible API candidates. Third, Pig selectively extracts the migration-related code fragments from the LLM outputs. Finally, it transplants the migrated code back into the original program with post-processing to ensure semantic correctness and consistency. We demonstrate the effectiveness of Pig by evaluating it on 364 API-level migration tasks, where it improves the average success rate of the baseline approach by 53.5% across seven different LLM models.Keywords
This publication has 29 references indexed in Scilit:
- DeepMig: A transformer-based approach to support coupled library and code migrationsInformation and Software Technology, 2024
- Refactoring Programs Using Large Language Models with Few-Shot Examples2023
- MELT: Mining Effective Lightweight Transformations from Pull Requests2023
- SOAR: A Synthesis Approach for Data Science API Refactoring2021
- Learning to recommend third-party library migration opportunities at the API levelApplied Soft Computing, 2020
- Meditor: Inference and Application of API Migration Edits2019
- Towards Zero Knowledge Learning for Cross Language API Mappings2019
- Do developers update their library dependencies?Empirical Software Engineering, 2017
- SemDiff: Analysis and recommendation support for API evolution2009
- Catchup! capturing and replaying refactorings to support API evolution2005