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.82.0.dev20260504174719.tar.gz (264.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.82.0.dev20260504174719-py3-none-any.whl (307.9 kB view details)

Uploaded Python 3

File details

Details for the file openrewrite-8.82.0.dev20260504174719.tar.gz.

File metadata

File hashes

Hashes for openrewrite-8.82.0.dev20260504174719.tar.gz
Algorithm Hash digest
SHA256 a3619ca632f72ecd73568472c71058d892ef0f5935f7180eeb1e2cb4898980e1
MD5 03803e4af4314a06dbe0f030c2b096cc
BLAKE2b-256 d1754bdeb88874b5d5ed751e0c04d944120bad30dd8929de9b699628c6ccd83b

See more details on using hashes here.

File details

Details for the file openrewrite-8.82.0.dev20260504174719-py3-none-any.whl.

File metadata

File hashes

Hashes for openrewrite-8.82.0.dev20260504174719-py3-none-any.whl
Algorithm Hash digest
SHA256 bc85905d4ef3cc4c81a645be2a7fd54a337b6216d722d22682aa456467279445
MD5 660e46852fcbee280d275b0e9482ae99
BLAKE2b-256 d2330a55eedb019308f44de57ef501cd12813529c9c810609a44913a35e40c6e

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