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.84.0.dev20260603095127.tar.gz (304.0 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.84.0.dev20260603095127-py3-none-any.whl (346.6 kB view details)

Uploaded Python 3

File details

Details for the file openrewrite-8.84.0.dev20260603095127.tar.gz.

File metadata

File hashes

Hashes for openrewrite-8.84.0.dev20260603095127.tar.gz
Algorithm Hash digest
SHA256 64a05a606b6ab7ca169b2f060bbb988d7b5c08539062fd0363ba2655a52e50b4
MD5 21a2107261cf0c00d25104d80f5318c0
BLAKE2b-256 da3004a416680f0c3be4fd742dd39e8df1ad7b0f32b2ab753f41caf0f5652b94

See more details on using hashes here.

File details

Details for the file openrewrite-8.84.0.dev20260603095127-py3-none-any.whl.

File metadata

File hashes

Hashes for openrewrite-8.84.0.dev20260603095127-py3-none-any.whl
Algorithm Hash digest
SHA256 2477ecf0c7043e9d87f99c65ffdf6bdf539bda94a6bafef1541ff8650901641f
MD5 87fe4d6d43c2e7c304649d910cbbb8d1
BLAKE2b-256 6b4dd76301cde5e60462748dd1ef35280b11e3c8ca37054e8157e8a70189d87c

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