Skip to main content

Intelligent Python dependency upgrade and auto-migration tool

Project description

autopatch ๐Ÿ› ๏ธ

autopatch is an intelligent Python dependency upgrade and breaking change migration tool. It detects public API breaking changes between package versions, scans your codebase to find where you use them, and suggests/applies patches automatically.


The Problem

When upgrading packages (e.g., pydantic from v1 to v2, or requests versions), developers face breaking changes:

  • Functions or classes get removed.
  • Method parameters are renamed or deleted.
  • Mandatory arguments are added without defaults.

Currently, developers find these changes through runtime crashes, linters, or reading massive changelogs.

The Solution

autopatch automatically:

  1. Downloads and isolates target package versions from PyPI.
  2. Parses ASTs of both versions to extract and diff public interfaces.
  3. Scans your local codebase to locate usages of deleted or changed symbols.
  4. Generates and applies unified diff patches to automatically migrate your codebase (with optional LLM assistance).

Quick Start

Installation

Install autopatch from source:

pip install -e .

Basic Usage

To analyze upgrades for a specific package, specify the package name, the source version, and the target version:

# Scan current directory for breaking changes from package updates
autopatch package_name --from 1.10.0 --to 2.0.0

Auto-Patching

To generate and apply migration patches directly:

# Add --patch to generate and apply fixes (optionally uses OPENAI_API_KEY/GEMINI_API_KEY)
autopatch package_name --from 1.10.0 --to 2.0.0 --patch

Engineering Design

                     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                     โ”‚  User Codebase   โ”‚
                     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                              โ”‚ 1. Parse Imports
                              โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚  PyPI API   โ”œโ”€โ”€โ”€โ”€โ”€โ–บโ”‚  Package Sources โ”œโ”€โ”€โ”€โ”€โ”€โ–บโ”‚ AST Analyzer โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ 2.   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ 3.   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                 Download                             โ”‚
                                                      โ–ผ
                                               โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                                               โ”‚   API Diff   โ”‚
                                               โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                                      โ”‚ 4. Detect Breaks
                                                      โ–ผ
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Patch Apply โ”‚โ—„โ”€โ”€โ”€โ”€โ”€โ”ค Patch Generator  โ”‚โ—„โ”€โ”€โ”€โ”€โ”€โ”ค Symbol Match โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ 6.   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜ 5.   โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
  1. AST Extraction: autopatch uses standard Python ast.NodeVisitor to traverse modules without importing or running the code, keeping the process fast and safe.
  2. Diff Signature Validation: Standard signature matching checks positional, keyword-only, default values, and parameter existence.
  3. Intelligent LLM Patching: Integrates seamlessly with OpenAI/Gemini APIs to generate context-aware code refactoring.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

depshift-0.1.0.tar.gz (13.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

depshift-0.1.0-py3-none-any.whl (16.1 kB view details)

Uploaded Python 3

File details

Details for the file depshift-0.1.0.tar.gz.

File metadata

  • Download URL: depshift-0.1.0.tar.gz
  • Upload date:
  • Size: 13.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.1

File hashes

Hashes for depshift-0.1.0.tar.gz
Algorithm Hash digest
SHA256 657f766350abc659f85f637e19e324767317f137ebd35b2dc6ac1476c21f0901
MD5 54dfaf96afedf6a4010d77f64a1c343a
BLAKE2b-256 9fde27cf724428788bc4ef5cafe3aceb37c7b0b355eddfa1b9b818bde19e2946

See more details on using hashes here.

File details

Details for the file depshift-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: depshift-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 16.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.1

File hashes

Hashes for depshift-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 64c8ab2962a3e6292773569e4327f4c63f4716a6ff7410a64971d5d62c3762d4
MD5 ac8872dce27903b785f69a5258b05e81
BLAKE2b-256 b6e25a5fe02e210330423a724758c7cd4cad32a3895715ff7a2604abf8ef9f60

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page