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.76.0.dev20260318162210.tar.gz (256.3 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.76.0.dev20260318162210-py3-none-any.whl (300.9 kB view details)

Uploaded Python 3

File details

Details for the file openrewrite-8.76.0.dev20260318162210.tar.gz.

File metadata

File hashes

Hashes for openrewrite-8.76.0.dev20260318162210.tar.gz
Algorithm Hash digest
SHA256 df65ac1daa47e78436508eefe8dc5f7718420eafd959a9b633831825adcb526e
MD5 6d1de681f8c2d8816fc84613240b3b26
BLAKE2b-256 586ce46800589e8c5610c23aad22da585983be90229b98b34b5c8a9206566339

See more details on using hashes here.

File details

Details for the file openrewrite-8.76.0.dev20260318162210-py3-none-any.whl.

File metadata

File hashes

Hashes for openrewrite-8.76.0.dev20260318162210-py3-none-any.whl
Algorithm Hash digest
SHA256 50c71030a67ef95e739e805676f177a5bd033396a0000d33e8c7f2033de21412
MD5 b7fa54a68b6e4770496bae1353a65612
BLAKE2b-256 b8a5d3e7ac319c531db1cb58fafa05fa3df1b6ff4e6af459e0b7df63ed5a4302

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