Pig: Leveraging Large Language Models for Python Library Migrations
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.
Authors
- Wonseok Oh (ORCID: https://orcid.org/0000-0002-3124-7415)
- Hakjoo Oh (ORCID: https://orcid.org/0000-0002-1900-7654)
- Gabin An (ORCID: https://orcid.org/0000-0002-6521-8858)
- Miryeong (ORCID: https://orcid.org/0009-0001-7987-3917)
Institutions
- Korea University (KR)
Publication Details
- Journal
- Proceedings of the ACM on software engineering.
- Published
- 2026-06-30
- DOI
- https://doi.org/10.1145/3797072
- Primary Topic
- Computational Physics and Python Applications
- Type
- article
- Field-Weighted Citation Impact
- 0.00