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.dev20260501142807.tar.gz (262.9 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.dev20260501142807-py3-none-any.whl (306.5 kB view details)

Uploaded Python 3

File details

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

File metadata

File hashes

Hashes for openrewrite-8.82.0.dev20260501142807.tar.gz
Algorithm Hash digest
SHA256 e6c43293f1815f5e3c3ff6ffbc06f5454afbc1191d2b0e0599b6f1ca8ccaea51
MD5 8e6a97f5fc0c8d3269dd4ffab13bf3f0
BLAKE2b-256 afdbc729b202f1d4fa2e4994d707c4934f7cc392fadf9d0e721e69f973712921

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for openrewrite-8.82.0.dev20260501142807-py3-none-any.whl
Algorithm Hash digest
SHA256 88030d806c31eb58557d38edae4d5951ce8dc8786c2a881a433e64ab451ff274
MD5 75528257a75106e415af3123fa029070
BLAKE2b-256 6d07291a10e36f14cb3ce3c5730fdfd5db4a61549c98145e6d7f97fe2ae0b686

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