zester
GuidesModules

pip

The pip.* family of state modules.

ModuleSummary
pip.installedEnsure a Python package is installed via pip, optionally pinned or from a requirements file.

All states also accept the full set of requisite parameters and Salt-parity state attributes — see Dependencies & Requisites.


pip.installed

Ensure a Python package is installed via pip, optionally pinned or from a requirements file.

Source: pkg/state/modules/pip/pip_installed.go


pip.installed ensures a Python package (name, defaulting to the state ID) is installed via bin (defaulting to pip3). Declaring requirements switches to installing from a requirements.txt file instead — name/version are then ignored for the install itself, though name still names the state.


Parameters

ParameterTypeRequiredDefaultDescription
namestringNoState IDpip package name; defaults to the state ID; ignored when requirements is set
versionstringNo(none)optional pinned version (e.g. 1.2.3), appended as package==version
requirementsstringNo(none)path to a requirements.txt file; when set, name is ignored for install
binstringNopip3path or name of the pip binary to use; defaults to pip3

Effects

Check

With requirements set, ALWAYS reports a change: a requirements file cannot be verified without actually running the install. Otherwise runs <bin> show <name>; a non-zero exit means the package needs installing. When version is declared and the package is present, parses the Version: line from pip show output and reports a change on any mismatch (compared as strings, so pre-release suffixes matter).

Apply

Package mode: <bin> install <name>[==version]. Requirements mode: <bin> install -r <requirements>. Reports the package and bin in its details.

Revert

Package mode: <bin> uninstall -y <name>. Requirements mode: an explicit no-op (Changed: false) — there is no record of which packages a requirements file installed, so there is nothing safe to uninstall.


Examples

Install the latest version

The package name defaults to the state ID.

requests:
  pip.installed: []

Pin to a specific version

version makes exact version equality part of the desired state.

requests:
  pip.installed:
    - version: "2.28.0"

Install from a requirements file

requirements installs every dependency listed in the file; name is ignored for install.

myapp-dependencies:
  pip.installed:
    - requirements: /opt/myapp/requirements.txt
    - require:
      - pkg.installed:python3-pip

Use a virtual environment's pip

bin overrides the pip binary, e.g. to target a venv.

myapp-venv-requests:
  pip.installed:
    - name: requests
    - bin: /opt/myapp/venv/bin/pip

Install a package ad hoc

The bare positional argument is the package name.

zester '*' pip.installed requests

On this page