Python Fabric Example

Do you like this?

This short example shows you how to use Fabric library


1. Installing Fabric

Run this command: easy_install fabric
On Windows machine, you might encounter errors setting up Paramiko (a dependency of Fabric) since it cannot find vcvarsall.bat file. What you can do is downloading a setup file from Voidspace and then install Paramiko using the file. Then you can run easy_install fabric again.

2. Creating A In Your Project's Folder

A sample code is provided below:
from fabric.api import *

env.host_string = ""
env.password= "pass"

def ls():
    run("ls -l")

3. Run Fabric

Open a console and cd to your project's folder. And run the following command:
fab ls
Fabric will then call the ls() method in your and return the directory information to your output.

comments powered by Disqus