Skip to main content

Viper provides a simple API (Python and CLI) to easily manage large infrastructures.

Project description

Viper Infrastructure Commander

Viper provides a simple API (Python and CLI) to easily manage large infrastructures.

Getting Started


pip install -U viper-infra-commander

# Or install with batteries included

pip install -U "viper-infra-commander[batteries]"


# (Optional) enable tab completion
eval "$(viper autocomplete $(basename $SHELL))"

# See the help menu
viper -h

# Initialize SQLite DB
viper init -f

Viper in Action (Basic Mode)

Define a set of hosts in csv format (json and yml are also supported) in hosts.csv:

cat > hosts.csv << EOF

Define a task in

cat > << EOF
from viper import Task

def ping_command(host):
    return "ping", "-c", "1", host.ip

def ping():
    return Task(
        name="Ping once",

Perform the following actions:

  • Run the task on the set of hosts in parallel with 5 workers,
  • filter only the results where the task failed,
  • re-run the task on them,
  • store the results in DB
viper hosts:from-file hosts.csv \
        | viper hosts:run-task --max-worker 5 \
        | viper results:where returncode IS_NOT 0 \
        | viper results:re-run --indent 4

See the stdout of the final results from DB:

viper results \
        | viper results:final \
        | viper results:format "{host.hostname}: {stdout}"

Export the results to a csv file:

viper results --final \
        | viper results:to-file results.csv --indent 4

Define a job using the Python API (CLI and Python API are almost similar):

cat > << EOF
from viper import WhereConditions
from task import ping

def ping_and_export(hosts):
    return (

Run the job using CLI:

viper hosts:from-file hosts.csv \
        | viper run job.ping_and_export \
        | viper results:format "{host.hostname}: {stdout}"

Viperfile in Action (Advanced Mode)

Define a project with custom subcommands in viperfile:

cat > << EOF
from viper import Hosts, Task
from viper.project import Project, arg

foo = Project(prefix="foo")

@foo.hostgroup(args=[arg("-f", "--file", default="hosts.csv")])
def allhosts(args):
    return Hosts.from_file(args.file)

def remote_exec_command(host, command):
    return (

        arg("command", help="command to execute"),
        arg("-w", "--workers", type=int, default=1),
def remote_exec(hosts, args):
    return (
                name="Remote execute command",

See the auto generated custom subcommands:

viper --help

Run the job:

viper @foo:allhosts \
        | viper @foo:remote_exec "uname -a" --workers 5 \
        | viper results:to-file results.csv \
        | viper results:format "{} [{host.hostname}]: {returncode}: {stdout}"

Further Readings

API Docs with Examples ☞

Contributing To Viper

Contribution Guidelines ☞

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

viper-infra-commander-0.28.3.tar.gz (29.3 kB view hashes)

Uploaded source

Built Distribution

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page