pip
Manages Python packages via pip. Supports version pinning, virtualenvs, and custom pip commands.
Parameters
| Parameter | Required | Default | Description |
|---|---|---|---|
package |
Yes | -- | Package name. |
state |
Yes | -- | Desired state: present, absent, or latest. |
version |
No | -- | Specific version to install (e.g., 2.28.0). |
extra_args |
No | -- | Additional arguments passed to pip install (space-separated). |
pip_cmd |
No | pip3 |
The pip command to use. |
virtualenv |
No | -- | Path to a virtualenv. If set, uses <virtualenv>/bin/<pip_cmd>. |
States
present-- Ensure the package is installed. Ifversionis specified and the installed version differs, upgrade to the specified version.absent-- Uninstall the package.latest-- Upgrade the package to the latest version (pip install --upgrade).
Idempotency
Runs pip show <package> to check if the package is installed and its current version. Compares against the desired state and version before acting.
Examples
Basic
resources:
- name: Install requests
type: pip
package: requests
Specific version
resources:
- name: Install requests 2.28.0
type: pip
package: requests
version: "2.28.0"
In a virtualenv
resources:
- name: Install Flask in app venv
type: pip
package: flask
virtualenv: /opt/myapp/venv
Latest version
resources:
- name: Keep boto3 up to date
type: pip
package: boto3
state: latest
Uninstall
resources:
- name: Remove deprecated package
type: pip
package: old-package
state: absent
Platform
Cross-platform. Requires pip to be installed.
Notes
- The
extra_argsparameter is split on whitespace and appended to thepip installcommand. - When using
virtualenv, the pip binary path is constructed as<virtualenv>/bin/<pip_cmd>. - The
lateststate always runspip install --upgrade, so it always reportschanged: true.