pyinfra - Python Infrastructure Automation Tool Logo

pyinfra - Python Infrastructure Automation

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 up to 10x faster.

Why Choose pyinfra?

  • Super Fast Execution Deploy to thousands of targets with predictable performance. Up to 10x faster than Ansible.
  • Instant Debugging Get realtime output from shell commands with no abstraction layer for immediate troubleshooting.
  • Declarative Operations Only make changes when needed with built-in diff checking and idempotent operations.
  • Fully Extendable Leverage the entire Python package ecosystem. Write inventory and operations in pure Python.
  • Agentless Architecture Deploy to any system with POSIX shell access. Zero dependencies on target systems.
  • Seamless Integration Pull inventory from Terraform, execute against Docker containers, integrate with your DevOps toolchain.
Getting Started Examples Repo

See It In Action

Write infrastructure automation in pure Python. No YAML, no DSL, just Python code.

deploy.py
# Install and configure nginx
from pyinfra.operations import apt, systemd

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


systemd.service(
    name="Restart and enable the nginx service",
    service="nginx.service",
    running=True,
    restarted=True,
    enabled=True,
)

Simple, Powerful, Pythonic

  • No new syntax to learn If you know Python, you know pyinfra
  • Full Python capabilities Use loops, conditions, functions, and any Python library
  • Type hints & IDE support Get autocomplete and inline documentation
  • Instant feedback See exactly what commands run on your servers in real-time

Perfect For Any Infrastructure Task

🖥️

Server Provisioning

Set up and configure new servers from bare metal to production-ready. Install packages, configure services, and manage users with idempotent operations.

🔄

Application Deployment

Deploy applications across your fleet with rolling updates, health checks, and automatic rollbacks. Perfect for web apps, microservices, and batch jobs.

⚙️

Configuration Management

Keep your infrastructure in sync with declarative configuration. Detect and fix drift automatically with diff checking and change tracking.

🔧

Ad-hoc Automation

Run one-off commands across hundreds of servers. Gather system information, perform updates, or execute maintenance tasks instantly.

🐳

Container Orchestration

Manage Docker containers and images. Deploy containers, configure networks, and handle volumes across your container infrastructure.

☁️

Cloud Infrastructure

Integrate with cloud providers and tools like Terraform. Pull dynamic inventory and automate cloud resource configuration seamlessly.

Getting Started Examples Repo

Join the Community

💬

Get Support

Join our active Matrix chat for help, discussions, and to connect with other pyinfra users and contributors.
 

Join Chat →
📚

Read the Docs

Comprehensive documentation with guides, API references, and examples to help you get started and master pyinfra.

View Docs →
🤝

Contribute

pyinfra is open source and welcomes contributions. Report bugs, suggest features, or contribute code on GitHub.

View on GitHub →

Frequently Asked Questions

Is pyinfra production-ready?

Yes! pyinfra is battle-tested and used by companies worldwide to manage production infrastructure. It has a stable API and comprehensive test coverage.

Can I migrate from Ansible?

Absolutely. Many teams have successfully migrated from Ansible to pyinfra. The concepts are similar, but the Python-based approach offers more flexibility and better performance.

Does it work with Windows?

pyinfra targets POSIX-compatible systems. While you can run pyinfra from Windows (via WSL), target systems should be Linux, macOS, or Unix-based systems.

How does it handle secrets?

pyinfra integrates with popular secret management tools. You can use environment variables, encrypted files, or integrate with HashiCorp Vault, AWS Secrets Manager, etc.

Can I use existing Python packages?

Yes! That's one of pyinfra's biggest advantages. You can import and use any Python package in your deployment scripts, from requests to boto3 to custom libraries.

What's the performance overhead?

Minimal. pyinfra uses efficient SSH multiplexing and parallel execution. It can manage thousands of servers simultaneously with low resource usage and predictable performance.

Getting Started Examples Repo