/pyinfra

pyinfra automates infrastructure using Python. It’s fast and scales from one server to thousands. Great for ad-hoc command execution, service deployment, configuration management and more.

Primary LanguagePythonMIT LicenseMIT

pyinfra

Note: this is the v3 branch, which is currently in beta. See the docs for v3. If needed the 2.x branch is here, but is in bugfix only mode.

pyinfra automates infrastructure using Python. It’s fast and scales from one server to thousands. Great for ad-hoc command execution, service deployment, configuration management and more.


DocumentationGetting StartedExamplesHelp & SupportContributing

Chat ⇒ #pyinfra on Matrix


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 pip:

pip 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