Skip to main content

OpenRewrite automated refactoring for Python.

Project description

OpenRewrite Python

OpenRewrite automated refactoring for Python source code.

Installation

pip install openrewrite

Quick Start

from rewrite.python import PythonParser
from rewrite import ExecutionContext

# Parse Python source code
parser = PythonParser()
ctx = ExecutionContext()
source_files = parser.parse(ctx, "example.py")

# Apply recipes to transform code
# ...

Writing Recipes

from dataclasses import dataclass, field
from rewrite import Recipe, option
from rewrite.python import PythonVisitor

@dataclass
class ChangeImport(Recipe):
    """Changes an import from one module to another."""

    old_module: str = field(metadata=option(
        display_name="Old module",
        description="The module to change imports from",
        example="flask"
    ))

    new_module: str = field(metadata=option(
        display_name="New module",
        description="The module to change imports to",
        example="flask_restful"
    ))

    @property
    def name(self) -> str:
        return "org.openrewrite.python.ChangeImport"

    @property
    def display_name(self) -> str:
        return "Change import"

    @property
    def description(self) -> str:
        return "Changes an import from one module to another."

    def editor(self) -> PythonVisitor:
        # Implementation...
        pass

Documentation

See docs.openrewrite.org for full documentation.

License

Moderne Source Available License - see LICENSE.md

Project details


Release history Release notifications | RSS feed

Download files

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

Source Distribution

openrewrite-8.73.0.dev20260204232430.tar.gz (199.6 kB view details)

Uploaded Source

Built Distribution

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

openrewrite-8.73.0.dev20260204232430-py3-none-any.whl (235.9 kB view details)

Uploaded Python 3

File details

Details for the file openrewrite-8.73.0.dev20260204232430.tar.gz.

File metadata

File hashes

Hashes for openrewrite-8.73.0.dev20260204232430.tar.gz
Algorithm Hash digest
SHA256 e13848052dd595068c9b55d8cba703e238684290f4952d9f01105de7eaf650bf
MD5 26ae3156e5d0b49145d8ba598877e9f8
BLAKE2b-256 5dda213878541f2e71586fa639a420a88c701a0a8cde17b7da6d01d461ffbf2e

See more details on using hashes here.

File details

Details for the file openrewrite-8.73.0.dev20260204232430-py3-none-any.whl.

File metadata

File hashes

Hashes for openrewrite-8.73.0.dev20260204232430-py3-none-any.whl
Algorithm Hash digest
SHA256 35dcd2b954c8d9f7dafb222917e1a3b4663f417a25efc43d5cf212856bc9f3d8
MD5 a1b9db7ae7f18f9eeda60c31b8c927ad
BLAKE2b-256 15a407a872d7754817541ade08757b2232f29930248b7f4408e68ae592b0c418

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