Documentation Index Fetch the complete documentation index at: https://mintlify.com/pyinfra-dev/pyinfra/llms.txt
Use this file to discover all available pages before exploring further.
The choco module manages packages on Windows using the Chocolatey package manager.
Functions
packages
Install, remove, or update Chocolatey packages.
from pyinfra.operations import choco
choco.packages(
name = "Install development tools" ,
packages = [ "git" , "vscode" ],
)
List of packages to ensure.
Whether the packages should be installed.
Whether to upgrade packages without a specified version.
Package versions can be pinned like gem: <pkg>:<version>
Example
from pyinfra.operations import choco
# Note: Assumes that 'choco' is installed and
# user has Administrator permission.
choco.packages(
name = "Install Notepad++" ,
packages = [ "notepadplusplus" ],
)
install
Install Chocolatey package manager.
from pyinfra.operations import choco
choco.install(
name = "Install Chocolatey" ,
)
This operation is not idempotent - it will always execute.
Requires Administrator permissions to install Chocolatey.
Common Use Cases
Install Chocolatey and Packages
from pyinfra.operations import choco
# Install Chocolatey
choco.install(
name = "Install Chocolatey package manager" ,
)
# Install packages
choco.packages(
name = "Install essential tools" ,
packages = [
"git" ,
"vscode" ,
"googlechrome" ,
"7zip" ,
],
)
Development Environment
from pyinfra.operations import choco
choco.packages(
name = "Install development tools" ,
packages = [
"git" ,
"nodejs" ,
"python" ,
"vscode" ,
"postman" ,
"docker-desktop" ,
],
)
Web Server Setup
from pyinfra.operations import choco
choco.packages(
name = "Install web server components" ,
packages = [
"nginx" ,
"php" ,
"mysql" ,
],
)
Install with Specific Versions
from pyinfra.operations import choco
choco.packages(
name = "Install specific versions" ,
packages = [
"python:3.11.0" ,
"nodejs:18.16.0" ,
],
)
System Utilities
from pyinfra.operations import choco
choco.packages(
name = "Install system utilities" ,
packages = [
"7zip" ,
"notepadplusplus" ,
"googlechrome" ,
"firefox" ,
"vlc" ,
"windirstat" ,
],
)
Update All Packages
from pyinfra.operations import choco
choco.packages(
name = "Update all packages to latest" ,
packages = [ "all" ],
latest = True ,
)
Chocolatey-Specific Tips
Administrator Permissions Required
Most Chocolatey operations require Administrator privileges. Ensure pyinfra is running with elevated permissions: # Run PowerShell as Administrator or use:
# pyinfra @winrm/administrator:password@hostname deploy.py
Checking Installed Packages
List all installed Chocolatey packages: from pyinfra.operations import server
server.shell(
name = "List installed packages" ,
commands = [ "choco list --local-only" ],
)
Search the Chocolatey repository: from pyinfra.operations import server
server.shell(
name = "Search for packages" ,
commands = [ "choco search nodejs" ],
)
Add custom package sources: from pyinfra.operations import server
server.shell(
name = "Add custom source" ,
commands = [
'choco source add -n="MySource" -s="https://mypackages.com/chocolatey"' ,
],
)
Pass additional options to Chocolatey: from pyinfra.operations import server
# Install with parameters
server.shell(
name = "Install with custom options" ,
commands = [
'choco install nodejs -y --version=18.16.0 --params="/InstallDir:C: \\ NodeJS"' ,
],
)
Important Notes
Chocolatey requires PowerShell and .NET Framework to be installed on the target Windows system.
All choco commands in pyinfra automatically include the -y flag for non-interactive installations.
For Windows Server management, consider using pyinfra @winrm connection method for remote deployments.