Change import
Recipe ID
org.openrewrite.python.ChangeImportArtifactopenrewriteChange a Python import from one module/name to another, updating all type attributions.
Single recipeProprietary
Usage
You’ll need the Moderne CLI configured before running the command below.
mod run . --recipe org.openrewrite.python.ChangeImport --recipe-option "old_module=collections" --recipe-option "new_module=collections.abc"If the recipe isn’t available locally, install it with:
mod config recipes pip install openrewriteOptions
| Name | Type | Description |
|---|---|---|
old_modulerequired | | The module to change imports from e.g. collections |
old_name | | The name to change (for 'from X import name' style). Leave empty for direct imports. e.g. Mapping |
new_modulerequired | | The module to change imports to e.g. collections.abc |
new_name | | The new name. If not specified, uses the old name. e.g. Mapping |
new_alias | | Optional alias for the new import |