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.74.0.dev20260218165240.tar.gz (234.4 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.74.0.dev20260218165240-py3-none-any.whl (277.0 kB view details)

Uploaded Python 3

File details

Details for the file openrewrite-8.74.0.dev20260218165240.tar.gz.

File metadata

File hashes

Hashes for openrewrite-8.74.0.dev20260218165240.tar.gz
Algorithm Hash digest
SHA256 d2dd131ee55c8e563e01e64ce1593ca48bfa54e5150836e69616f7381e713fd2
MD5 625ee94d20ce1f70a351aa07d7f011f8
BLAKE2b-256 9b476d5455b1b802d6832ce49f667cf777c35f307d10633158da65dfb17b902a

See more details on using hashes here.

File details

Details for the file openrewrite-8.74.0.dev20260218165240-py3-none-any.whl.

File metadata

File hashes

Hashes for openrewrite-8.74.0.dev20260218165240-py3-none-any.whl
Algorithm Hash digest
SHA256 e711652f0fd66b39bcc487f4b645d2d6b7eea3bf3a306bd953db166f89baa331
MD5 2bac6426b7b808167e67db4651871695
BLAKE2b-256 cd9225ec37cc153cdff97f59b158d8f45fda369a77da03be7c832c0bf84041e5

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