Skip to main content

High level SSH command execution

Project description

To find out what’s new in this version of Fabric, please see the changelog.

What is Fabric?

Fabric is a high level Python (2.7, 3.4+) library designed to execute shell commands remotely over SSH, yielding useful Python objects in return:

>>> from fabric import Connection
>>> result = Connection('web1.example.com').run('uname -s')
>>> msg = "Ran {.command!r} on {.connection.host}, got stdout:\n{.stdout}"
>>> print(msg.format(result))
Ran "uname -s" on web1.example.com, got this stdout:
Linux

It builds on top of Invoke (subprocess command execution and command-line features) and Paramiko (SSH protocol implementation), extending their APIs to complement one another and provide additional functionality.

How is it used?

Core use cases for Fabric include (but are not limited to):

  • Single commands on individual hosts:

    >>> result = Connection('web1').run('hostname')
    web1
    >>> result
    <Result cmd='hostname' exited=0>
  • Single commands across multiple hosts (via varying methodologies: serial, parallel, etc):

    >>> result = SerialGroup('web1', 'web2').run('hostname')
    web1
    web2
    >>> result
    {<Connection host=web1>: <Result cmd='whoami' exited=0>, ...}
  • Python code blocks (functions/methods) targeted at individual connections:

    >>> def disk_free(c):
    >>>     uname = c.run('uname -s', hide=True)
    >>>     if 'Linux' in uname:
    ...         command = "df -h / | tail -n1 | awk '{print $5}'"
    ...         return c.run(command, hide=True).stdout.strip()
    ...     err = "No idea how to get disk space on {}!".format(uname)
    ...     raise Exit(err)
    ...
    >>> disk_free(Connection('web1'))
    '33%'
  • Python code blocks on multiple hosts:

    >>> def disk_free(c):
    ...     # same as above!
    ...
    >>> {c: disk_free(c) for c in SerialGroup('web1', 'web2', 'db1')}
    {<Connection host=web1>: '33%', <Connection host=web2>: '17%', ...}

In addition to these library-oriented use cases, Fabric makes it easy to integrate with Invoke’s command-line task functionality, invoking via a fab binary stub:

  • Python functions, methods or entire objects can be used as CLI-addressable tasks, e.g. fab deploy;

  • Tasks may indicate other tasks to be run before or after they themselves execute (pre- or post-tasks);

  • Tasks are parameterized via regular GNU-style arguments, e.g. fab deploy --env=prod -d;

  • Multiple tasks may be given in a single CLI session, e.g. fab build deploy;

  • Much more - all other Invoke functionality is supported - see its documentation for details.

I’m a user of Fabric 1, how do I upgrade?

We’ve packaged modern Fabric in a manner that allows installation alongside Fabric 1, so you can upgrade at whatever pace your use case requires. There are multiple possible approaches – see our detailed upgrade documentation for details.

Download files

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

Source Distribution

fabric2-2.1.4.tar.gz (139.8 kB view details)

Uploaded Source

Built Distribution

fabric2-2.1.4-py2.py3-none-any.whl (46.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file fabric2-2.1.4.tar.gz.

File metadata

  • Download URL: fabric2-2.1.4.tar.gz
  • Upload date:
  • Size: 139.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for fabric2-2.1.4.tar.gz
Algorithm Hash digest
SHA256 b54548e20442c3d832d59e11e8222df3f699c375d904ccaeaf8b0d93e88e5c27
MD5 74cb2e3b6c9159d65e873b78955d5300
BLAKE2b-256 e4d193cda129a35abb2239fc567e14ab93ccf7597ded5afbf15f4a3e0438b5f4

See more details on using hashes here.

File details

Details for the file fabric2-2.1.4-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for fabric2-2.1.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 052ab311795060a32d40f634b2cb6f996ff26a06ea7e236f40c50f8b4d3b4c57
MD5 87d2e0aba6e9acfc5b2c87e8beddbcf5
BLAKE2b-256 f49702f9685cfbccd19a3d060aa867cd69f3280d19f0c8512110b0cebda47d3a

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page