Cette page est affichée en anglais. Une traduction française est en cours.
ConfigsJul 20, 2026·3 min de lecture

pyinfra — Automate Infrastructure with Python

pyinfra turns Python code into shell commands and runs them on your servers. It supports ad-hoc commands, declarative infrastructure operations, and scales from one server to thousands via SSH, Docker containers, or local execution.

Prêt pour agents

Installation agent prête

Cet actif peut être installé après choix du runtime, vérification du plan et exécution de la commande adaptée.

Native · 98/100Policy : autoriser
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Single
Confiance
Confiance : Established
Point d'entrée
pyinfra
Commande d'installation directe
npx -y tokrepo@latest install 0f62d8ba-8438-11f1-9bc6-00163e2b0d79 --target codex

À exécuter après confirmation du plan en dry-run.

Introduction

pyinfra is an infrastructure automation tool that uses Python as its configuration language. Instead of YAML or DSL-based playbooks, you write standard Python scripts that describe the desired state of your servers. pyinfra compiles these into shell commands and executes them over SSH, locally, or inside Docker containers. It is agentless and requires no software installed on target machines.

What pyinfra Does

  • Executes ad-hoc shell commands across one or many servers in parallel
  • Provides declarative operations for packages, files, services, users, and system configuration
  • Supports SSH, Docker, local, and custom connector backends
  • Generates change diffs showing what will be modified before applying
  • Handles facts (system state queries) and conditional logic using plain Python

Architecture Overview

pyinfra works in three stages: inventory resolution, operation compilation, and execution. The inventory defines hosts and groups using Python data structures. Operations are Python functions that describe desired state (e.g., ensure a package is installed). pyinfra collects facts from target hosts, computes the required changes, and executes shell commands through the chosen connector. All operations are idempotent by default.

Self-Hosting & Configuration

  • Install with pip install pyinfra on any machine with Python 3.8+
  • Define hosts in inventory files or pass them directly on the command line
  • Write deploy scripts using built-in operations from pyinfra.operations
  • Group hosts and assign data using Python dictionaries and variables
  • Use --dry flag to preview changes without applying them

Key Features

  • Pure Python configuration with full access to loops, conditionals, and libraries
  • Agentless architecture requiring only SSH access to target machines
  • Parallel execution across thousands of hosts with configurable concurrency
  • Built-in operations covering apt, yum, pip, files, systemd, git, and Docker
  • Instant dry-run mode showing exactly what commands will execute

Comparison with Similar Tools

  • Ansible — YAML-based with a steeper learning curve for complex logic; pyinfra uses native Python
  • SaltStack — Requires a master/minion architecture; pyinfra is agentless and push-based
  • Fabric — Imperative command runner; pyinfra adds declarative, idempotent operations
  • Chef/Puppet — Agent-based with Ruby DSLs; pyinfra is agentless with Python
  • Terraform — Focused on cloud resource provisioning; pyinfra manages server configuration

FAQ

Q: Do I need to install anything on the target servers? A: No. pyinfra is agentless and only requires SSH access and a POSIX shell on the remote hosts.

Q: Can pyinfra replace Ansible? A: For many use cases, yes. pyinfra handles the same configuration management tasks with Python instead of YAML, which simplifies complex logic.

Q: Does pyinfra support Windows targets? A: pyinfra primarily targets Linux and Unix systems. Windows support is limited and experimental.

Q: How does pyinfra handle secrets? A: You can use Python environment variables, vault libraries, or any secret manager since deploy files are standard Python scripts.

Sources

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires