Pig: Leveraging Large Language Models for Python Library Migrations
Miryeong Kang, Wonseok Oh, Gabin An, Hakjoo Oh
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.
Ask about this paper
Ask your agent about it.
Lune has read the top-tier papers around this one, so every answer names the papers it rests on.
Your agent calls
Lunesearch_papers
Free to start. No credit card required.
Terminal
Install the CLIlune papers get 29554133-e874-4593-9a3c-50091870d71cRelated papers
- An Empirical Study of Python Library Migration Using Large Language ModelsMohayeminul Islam, Ajay Kumar Jha, May Mahmoud, Ildar Akhmetov et al.ASE 2025 · 2 citations
- LLMs Meet Library Evolution: Evaluating Deprecated API Usage in LLM-Based Code CompletionChong Wang, Kaifeng Huang, Jian Zhang, Yebo Feng et al.ICSE 2025 · 3 citations
- The Fix Is Right at Hand: Fixing Incompatibility Errors Guided by Library Knowledge for Automatic Library UpgradeZhuotong Zhou, Susheng Wu, Junpeng Zhao, Bihuan Chen et al.ISSTA 2026
- Characterizing Python Library MigrationsMohayeminul Islam, Ajay Kumar Jha, Ildar Akhmetov, Sarah NadiFSE 2024 · 3 citations
- MigGPT: Harnessing Large Language Models for Automated Migration of Out-of-Tree Linux Kernel Patches Across VersionsPucheng Dang, Di Huang, Dong Li, Kang Chen et al.NeurIPS 2025 · 3 citations
