pyinfra is a free, open source cloud infrastructure management project written in Python and released under MIT. It has 6,000 GitHub stars, 547 forks and 160 open issues, and was last pushed 27 hours ago. On this registry it ranks #22 of 43 tracked projects in Cloud Infrastructure Management, with 5 head-to-head comparisons available. It gained 2 stars over the last 3 tracked days.

What is pyinfra?

What it is

pyinfra is a Python-based infrastructure automation tool that turns Python code into shell commands and runs those commands on remote servers. It lives in the configuration management and cloud infrastructure management space, and it targets SSH servers, the local machine, and Docker containers through a connector system. The project is written in Python, licensed under MIT, and has been developed for roughly twelve years. Its own description frames it as "ansible but Python instead of YAML."

The concrete problem it solves is the gap between ad-hoc shell work and heavyweight declarative configuration files. Instead of writing YAML playbooks, a user writes ordinary Python, using packaged operations that describe desired state rather than raw commands. Those operations are idempotent, which makes diffs and dry runs possible before anything changes on a host. Because execution is agentless, nothing has to be installed on the target beyond shell access, and the same inventory can address one machine or thousands.

Key capabilities

  • Idempotent operations that support diffs and dry runs before changes are applied.
  • Agentless execution against anything reachable over shell access.
  • Parallel execution that scales from a single host to thousands with predictable performance.
  • Realtime stdin, stdout, and stderr streaming for debugging, exposed through the -vvv flag.
  • Extensibility through the entire Python package ecosystem.
  • Connectors for Docker, Terraform, Vagrant, and other targets, alongside SSH and local execution.
  • A CLI that can run either ad-hoc shell commands or saved operation files against a named inventory.

Who uses it and how

  • Running ad-hoc commands over SSH, for example pyinfra my-server.net exec -- echo "hello world".
  • Applying package state directly from the command line, such as installing iftop on a Docker target with pyinfra @docker/ubuntu apt.packages iftop update=true _sudo=true.
  • Writing reusable deployment files in Python, where operations such as apt.packages are imported and called with a name, package list, and sudo flag.
  • Defining target hosts in an inventory file, such as one listing both @docker/ubuntu and a test server, then running an inventory and a deploy file together.
  • Targeting the local machine or a container for testing a deployment before it reaches real servers.

Getting started

Install with uv tool install pyinfra, then execute commands over SSH or against connectors such as @docker/ubuntu and @local. Operations can be run inline from the CLI or saved into Python files and executed against an inventory.

When to use it โ€” and when not to

It is a reasonable replacement for paid configuration management products when the team already writes Python and wants to avoid a YAML domain-specific language. A self-hoster operates the control machine and its Python environment rather than a server component, since execution is agentless. The main weakness visible in the facts is the open issue count of 160, which suggests a project with a live backlog to review before adopting it for critical infrastructure.

project readme (upstream, from github) โ€” read inline

pyinfra

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. Fast and scales from one server to thousands. Think ansible but Python instead of YAML, and a lot faster.


Getting StartedExamples RepoChat on Matrix

DocumentationHelp & SupportContributing


Why pyinfra? Design features include:

  • ๐Ÿš€ Super fast execution over thousands of hosts with predictable performance.
  • ๐Ÿšจ Instant debugging with realtime stdin/stdout/stderr output (-vvv).
  • ๐Ÿ”„ Idempotent operations that enable diffs and dry runs before making changes.
  • ๐Ÿ“ฆ Extendable with the entire Python package ecosystem.
  • ๐Ÿ’ป Agentless execution against anything with shell access.
  • ๐Ÿ”Œ Integrated with connectors for Docker, Terraform, Vagrant and more.

Quickstart

Install pyinfra with uv:

uv tool install pyinfra

Now you can execute commands on hosts via SSH:

pyinfra my-server.net exec -- echo "hello world"

Or target Docker containers, the local machine, and other connectors:

pyinfra @docker/ubuntu exec -- echo "Hello world"
pyinfra @local exec -- echo "Hello world"

As well as executing commands you can define state using operations:

# Install iftop apt package if not present
pyinfra @docker/ubuntu apt.packages iftop update=true _sudo=true

Which can then be saved as a Python file like deploy.py:

from pyinfra.operations import apt

apt.packages(
    name="Ensure iftop is installed",
    packages=['iftop'],
    update=True,
    _sudo=True,
)

The hosts can also be saved in a file, for example inventory.py:

targets = ["@docker/ubuntu", "my-test-server.net"]

And executed together:

pyinfra inventory.py deploy.py

Now you know the building blocks of pyinfra! By combining inventory, operations and Python code you can deploy anything.

See the more detailed getting started or using operations guides. See how to use inventory & data, global arguments and the CLI or check out the documented examples.


PyPI version PyPi downloads Docs status Execute tests status Codecov Coverage MIT Licensed

Frequently asked questions

Is pyinfra free to use?

pyinfra is open source under the MIT licence. There is no licence fee and no seat count โ€” you can self-host it or, where the project offers one, pay a vendor for a managed version instead.

What does pyinfra do?

๐Ÿ”ง pyinfra turns Python code into shell commands and runs them on your servers. Execute ad-hoc commands and write declarative operations. Target SSH servers, lo

What is pyinfra written in?

pyinfra is primarily written in Python. Its source is publicly available at https://github.com/pyinfra-dev/pyinfra, and it has 6,000 GitHub stars.