Replace a Python dependency
ProprietaryReplace each declaration of a Python dependency with another package, keeping its environment marker and the group or extra it is declared in, in each project whose sources import the new package's module. Remove it instead where no new package is given, where the project does not import the new module, or where the same list already declares the new package. Edits pyproject.toml ([project] dependencies, [project.optional-dependencies], [dependency-groups], Hatch's environments, uv's and PDM's development dependencies and Poetry's dependency tables), Pipfile, requirements*.txt and requirements*.in, setup.cfg's install_requires and extras_require, and the requirement strings in setup.py's lists, nested projects included, whether or not their dependencies could be resolved. With unlessImporting, a project whose sources still import one of those modules unguarded keeps its declarations, and gets the new package declared beside them once its sources import the new module. uv.lock, poetry.lock, pdm.lock and Pipfile.lock are regenerated natively to match.
org. openrewrite. python. migrate. ReplaceDependencyRequired
The name of the package to replace, as PyPI spells it.
Optional
The package that takes its place, as PyPI spells it. Without it, each declaration is removed.
The version constraint the new package is declared with, as PEP 440 writes it.
Modules that, imported by a project's Python sources outside an if or a try, keep its declarations of the package, since that import would fail without it. An import of a submodule counts. Separate values with commas.
The module the new package installs. A project that keeps the package, and whose sources import this module, gets the new package declared beside it. Defaults to the new package's name, with each - read as _.
mod run . --recipe= org. openrewrite. python. migrate. ReplaceDependency \
-P packageName= retryInstall it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.