Registry / devops / fabric

fabric

JSON →
library3.2.3pypypi✓ verified 26d ago

Fabric is a high-level Python library for streamlining SSH command execution and application deployment. It is currently at version 3.2.3 and releases updates on an as-needed basis, typically for bug fixes or minor enhancements, building on Invoke and Paramiko.

pip install fabric
INSTALL
IMPORT
SIG · FABRIC
F
fabric
devopspythonv3.2.3
Install
3.6s avg
Import
749ms
Disk
42MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v3.2.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.774s · 43.7MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.6s · import 0.724s · 44MB
42MB installed
● package 42MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Connection
from fabric import Connection
from fabric.api import env
Fabric 2.x+ removed the global 'env' state from Fabric 1.x. All operations now happen on a 'Connection' object.
task
from fabric import task
from fabric.api import task
While 'task' might exist in 1.x 'fabric.api', the modern Fabric 2.x+ API directly imports from 'fabric'.

Create a `fabfile.py` with tasks. Each task receives a `Connection` object `c` as its first argument. Run tasks from the command line using `fab -H user@host task_name`.

# fabfile.py from fabric import Connection, task @task def hello(c): """ Runs a simple command on the remote host. Example usage: fab -H user@localhost hello Note: For 'localhost' to work, an SSH server must be running and your user configured for SSH access. """ print(f"Connecting to {c.host} as {c.user or 'default'}...") # Run a command, hiding the command itself from stdout, only showing output result = c.run("echo Hello from $(hostname)", hide=True) print(f"Output: {result.stdout.strip()}")
fab --version
Debug
Known issues
breakingFabric 2.x and 3.x are NOT backward compatible with Fabric 1.x. The API was completely rewritten, moving from global state ('env') to an object-oriented design centered around the 'Connection' object.
fix
Rewrite Fabric 1.x scripts to use the new `Connection` object-based API. Consult the Fabric 2.x migration guide for details.
affects: 1.x to 2.x+
gotchaGlobal state ('env') from Fabric 1.x is gone. Tasks now receive a `Connection` object (`c`) as their first argument, which holds all connection-specific information and methods.
fix
Access connection properties via `c.host`, `c.user`, `c.config`, etc., and call methods like `c.run()`, `c.sudo()`.
affects: 2.x, 3.x
gotchaThe global functions `run()`, `sudo()`, `local()`, `put()`, `get()` from Fabric 1.x are now methods of the `Connection` object (e.g., `c.run()`, `c.sudo()`).
fix
Replace calls like `run('command')` with `c.run('command')`. Similarly for `sudo`, `local`, `put`, `get`.
affects: 2.x, 3.x
gotchaContext managers like `cd()`, `warn_only()`, `settings()` from Fabric 1.x are also now methods of the `Connection` object (e.g., `with c.cd('/path'):`).
fix
Ensure all context manager usage is prefixed with the `Connection` object, e.g., `with c.cd('/tmp'): c.run('ls')`.
affects: 2.x, 3.x
gotchaConfiguration is handled via the `Config` object or directly on `Connection` instances, not global dictionaries. Passing parameters to tasks requires explicit arguments or configuration.
fix
Define task parameters explicitly (`@task(arg1='default')`), or configure connection parameters via `Connection` constructor, or `fab` CLI flags (`-H`, `-u`, `-i`, `-p`).
affects: 2.x, 3.x
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'fabric.api'
This error occurs when trying to import `fabric.api`, which was part of Fabric 1.x, but you have Fabric 2.x or 3.x installed. The API was completely re-architected in Fabric 2.0 and `fabric.api` no longer exists.
fix
Rewrite your imports to use the new Fabric 2.x/3.x API, primarily importing `Connection`, `task`, and other components directly from the `fabric` package. For example, instead of `from fabric.api import run`, use `from fabric import Connection, task` and call methods on a `Connection` object (e.g., `c = Connection('host'); c.run('command')`).
AttributeError: 'Connection' object has no attribute 'run'
This error happens when you're using Fabric 2.x or 3.x but attempting to call `run()` or `sudo()` as global functions (like in Fabric 1.x) instead of calling them as methods on an instantiated `Connection` object.
fix
Ensure you create a `Connection` object and call `run()` or `sudo()` as methods of that object. For example, `from fabric import Connection; c = Connection('your_host'); c.run('command')`.
Fatal error: sudo() received nonzero return code 1 while executing!
This typically means a command executed via `sudo()` on the remote host failed and returned a non-zero exit code, which Fabric interprets as an error and by default aborts the execution. This can be due to incorrect commands, insufficient privileges, or a missing shell context.
fix
To prevent Fabric from aborting and inspect the failure, use `with Connection(host).settings(warn_only=True): result = c.sudo('your_command')`. Then check `result.failed` or `result.return_code` to handle the error programmatically. Also, ensure the remote command is syntactically correct and the user has `sudo` privileges for it. If the error is 'sudo: cd: command not found', ensure `shell=True` (the default) is used to allow shell features like `cd` to work correctly within `sudo` calls.
Connection refused
This is a common SSH error indicating that the remote host actively refused the connection attempt. This is often not a Fabric library error itself, but rather an issue with the SSH server on the remote machine (e.g., not running, firewall blocking the port, incorrect hostname/port, or incorrect SSH daemon configuration).
fix
Verify that the SSH daemon is running on the remote server, firewalls (local and network) allow connections on port 22 (or your custom SSH port), the hostname/IP and port are correct in your Fabric `Connection` arguments, and that the remote server's SSH configuration is not explicitly denying access for your user or connection type.
Upgrade
Version history
3.2.3latest on PyPI · released Apr 6, 2026
Audit
Dependencies
invokerequiredFabric builds upon Invoke for its task execution framework and CLI.
paramikorequiredFabric uses Paramiko as its underlying SSH client library.
Agent activity
25 hits · last 30 days
node
22
OpenAI (training)
1
Resources
fabric — pip install fabric · libregistry