The brew module manages packages and casks on macOS using Homebrew package manager.
Functions
packages
Install, remove, or update brew packages.
from pyinfra.operations import brew
brew.packages(
name = "Install development tools" ,
packages = [ "vim" , "git" ],
update = True ,
)
List of packages to ensure.
Whether the packages should be installed.
Whether to upgrade packages without a specified version.
Run brew update before installing packages.
Run brew upgrade before installing packages.
Package versions can be pinned like brew: <pkg>@<version>
Examples
Basic Installation
Latest Versions
Version Pinning
from pyinfra.operations import brew
# Update package list and install packages
brew.packages(
name = "Install Vim and vimpager" ,
packages = [ "vimpager" , "vim" ],
update = True ,
)
update
Update brew package repositories.
from pyinfra.operations import brew
brew.update(
name = "Update brew repositories" ,
)
This operation is not idempotent - it will always execute.
upgrade
Upgrade all brew packages.
from pyinfra.operations import brew
brew.upgrade(
name = "Upgrade all packages" ,
)
This operation is not idempotent - it will always execute.
casks
Install, remove, or update brew casks (applications).
from pyinfra.operations import brew
brew.casks(
name = "Install desktop applications" ,
casks = [ "firefox" , "visual-studio-code" ],
)
Whether the casks should be installed.
Whether to upgrade casks without a specified version.
Run brew cask upgrade before installing casks.
Cask versions can be pinned like brew: <pkg>@<version>
Example
from pyinfra.operations import brew
brew.casks(
name = "Upgrade and install the latest cask" ,
casks = [ "godot" ],
upgrade = True ,
latest = True ,
)
cask_upgrade
Upgrade all brew casks.
from pyinfra.operations import brew
brew.cask_upgrade(
name = "Upgrade all casks" ,
)
This operation is not idempotent - it will always execute.
tap
Add or remove brew taps (third-party repositories).
from pyinfra.operations import brew
brew.tap(
name = "Add a brew tap" ,
src = "homebrew/cask-fonts" ,
)
The name of the tap (e.g., user/repo).
Whether this tap should be present or not.
Examples
Simple Tap
Tap from URL
Custom URL
Multiple Taps
from pyinfra.operations import brew
brew.tap(
name = "Add a brew tap" ,
src = "includeos/includeos" ,
)
Common Use Cases
Development Environment Setup
from pyinfra.operations import brew
# Update brew
brew.update(
name = "Update Homebrew" ,
)
# Install development tools
brew.packages(
name = "Install development tools" ,
packages = [
"git" ,
"vim" ,
"tmux" ,
"wget" ,
"curl" ,
"jq" ,
"[email protected] " ,
"node" ,
],
)
# Install desktop applications
brew.casks(
name = "Install development applications" ,
casks = [
"visual-studio-code" ,
"iterm2" ,
"docker" ,
"postman" ,
],
)
Install from Custom Tap
from pyinfra.operations import brew
# Add custom tap
brew.tap(
name = "Add custom tap" ,
src = "homebrew/cask-fonts" ,
)
# Install from tap
brew.casks(
name = "Install fonts" ,
casks = [
"font-fira-code" ,
"font-jetbrains-mono" ,
],
)
Full System Update
from pyinfra.operations import brew
# Update brew
brew.update(
name = "Update Homebrew" ,
)
# Upgrade all packages
brew.upgrade(
name = "Upgrade all packages" ,
)
# Upgrade all casks
brew.cask_upgrade(
name = "Upgrade all casks" ,
)
from pyinfra.operations import brew
brew.packages(
name = "Install database tools" ,
packages = [
"postgresql@14" ,
"redis" ,
"mysql" ,
],
update = True ,
)
Install Browser for Testing
from pyinfra.operations import brew
brew.casks(
name = "Install browsers" ,
casks = [
"google-chrome" ,
"firefox" ,
"microsoft-edge" ,
],
)
Homebrew-Specific Tips
Homebrew provides service management for installed packages: from pyinfra.operations import server
# Start a service
server.shell(
name = "Start PostgreSQL" ,
commands = [ "brew services start postgresql@14" ],
)
# Stop a service
server.shell(
name = "Stop PostgreSQL" ,
commands = [ "brew services stop postgresql@14" ],
)
# Restart a service
server.shell(
name = "Restart PostgreSQL" ,
commands = [ "brew services restart postgresql@14" ],
)
Remove old versions of installed packages: from pyinfra.operations import server
server.shell(
name = "Clean up old versions" ,
commands = [ "brew cleanup" ],
)
Check Installation Health
Verify Homebrew installation: from pyinfra.operations import server
server.shell(
name = "Run brew doctor" ,
commands = [ "brew doctor" ],
)