← All recipes
Moderne licensed

Change import

Recipe IDorg.openrewrite.python.ChangeImportArtifactopenrewrite

Change 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 openrewrite

Options

NameTypeDescription
old_modulerequiredThe module to change imports from
e.g. collections
old_nameThe name to change (for 'from X import name' style). Leave empty for direct imports.
e.g. Mapping
new_modulerequiredThe module to change imports to
e.g. collections.abc
new_nameThe new name. If not specified, uses the old name.
e.g. Mapping
new_aliasOptional alias for the new import