Add Python dependency

MSAL

Add a dependency to a Python project. Supports pyproject.toml (with scope/group targeting), requirements.txt, and Pipfile. When onlyIfUsing is set, the dependency is added only to projects with a Python file that imports that module. For pyproject.toml, uv.lock, poetry.lock, and pdm.lock are regenerated natively without executing the package manager. For Pipfile, Pipfile.lock is regenerated natively by consulting the project's package index over the network. Not safe to use as a precondition: consults the package index over the network and publishes per-project state shared with other dependency recipes.

org.openrewrite.python.AddDependency

Required

The PyPI package name to add.

Optional

The PEP 508 version constraint (e.g., >=2.28.0).

The dependency scope to add to. For pyproject.toml this targets a specific TOML section. For requirements files, null matches all files, empty string matches only requirements.txt, and a value like dev matches requirements-dev.txt. Defaults to project.dependencies.

The group name, required when scope is project.optional-dependencies or dependency-groups.

Only add the dependency to a project when one of its Python source files imports this module, matched the way org.openrewrite.python.search.UsesImport matches it. A file belongs to the project of its nearest enclosing dependency file. Imports are read as they stand at the start of the recipe run, so in a migration name the module being migrated away from. Leave unset to add the dependency unconditionally.

mod run . --recipe=org.openrewrite.python.AddDependency \ -P packageName=requests

Install it once from Recipe actions, then run it on every repository under the current directory. New to the Moderne CLI? Set it up.