Skip to main content

Infrastructure automation with Python

pyinfra turns Python code into shell commands and runs them on your servers. Execute ad-hoc commands and write declarative operations. Target SSH servers, local machine, and Docker containers.

Quick Start

Get up and running with pyinfra in minutes

1

Install pyinfra

Install pyinfra using uv, pip, or your preferred package manager.
uv tool install pyinfra
2

Run your first command

Execute a command on a remote server via SSH or on your local machine.
pyinfra my-server.net exec -- echo "Hello from pyinfra"
You can also target Docker containers (@docker/ubuntu), the local machine (@local), and other connectors.
3

Use operations

Define infrastructure state using declarative operations.
pyinfra @docker/ubuntu apt.packages iftop update=true _sudo=true
This ensures the iftop package is installed, running updates if needed.
4

Create a deploy file

Save your infrastructure code as a Python file for repeatable deployments.
deploy.py
from pyinfra.operations import apt, systemd

apt.packages(
    name="Install nginx",
    packages=["nginx"],
    update=True,
    _sudo=True,
)

systemd.service(
    name="Ensure nginx is running",
    service="nginx",
    running=True,
    enabled=True,
    _sudo=True,
)
Run with: pyinfra inventory.py deploy.py

Explore by Topic

Dive deeper into pyinfra’s capabilities

Core Concepts

Learn about operations, facts, inventory, state, and connectors

Operations Reference

Explore 40+ operations for package managers, services, files, and databases

CLI Reference

Master the pyinfra command-line interface and its options

API Reference

Deep dive into the Python API for advanced use cases

Key Features

Why developers choose pyinfra for infrastructure automation

Super Fast Execution

Execute over thousands of hosts with predictable performance and parallel execution.

Idempotent Operations

Safe deployments with dry runs and diffs before making any changes to your infrastructure.

Python-Based

Write infrastructure as Python code, not YAML. Use the entire Python ecosystem.

Multiple Connectors

Connect to SSH servers, Docker containers, local machine, and integrate with Terraform and Vagrant.

Ready to automate your infrastructure?

Get started with pyinfra and deploy with confidence using Python.

Start Building