Small tool to interact with shell pipes
Latest commit 8a99f4c Feb 22, 2017 @gawel pep8
Failed to load latest commit information.
chut pep8 Feb 21, 2017
docs dealing more gracefully with spaces Apr 4, 2016
.chut 100% coverage Mar 8, 2013
.travis.yml py35 support Jan 28, 2016 py35 support Jan 28, 2016
README.rst add pathlib Feb 25, 2015 initial commit Oct 28, 2012
buildout.cfg fabric support Mar 9, 2013 fabric support Mar 9, 2013
setup.cfg py35 support Jan 28, 2016 Back to development: 0.17 Apr 20, 2016 temporarily change the env using a with statement Mar 31, 2016
tox.ini run all tests Jan 28, 2016



Chut is a small tool to help you to interact with shell pipes and commands.

Basically it will help to write some shell script in python

This is more like a toy than a real tool but... It may be useful sometimes.

It's tested with py2.6+ and py3.2+:

Full documentation can be found here

Quick quick start

Get the chutify script:

$ wget
$ chmod +x chutify

Write a console script:

$ cat << EOF >
from chut import *

__version__ = '0.1'

def mycmd(args):
    """Usage: %prog [options] <directory>

    Print all chut scripts found in <directory>


    for filename in find('-name *.py') | grep('@console_script'):

Run chutify in development mode:

$ ./chutify --devel
chmod +x bin/mycmd

And use/debug the newly created script:

$ ./bin/mycmd -h

When your script is ready for production then generate the standalone version:

$ ./chutify
chmod +x dist/scripts/mycmd

Also have a look at the examples.


Using pip:

$ pip install chut

This will also install docopt and allow you to use the @console_script decorator.

Another option is to get chutify standalone version:

$ wget
$ chmod +x chutify

Quick start

Import the shell:

>>> import chut as sh

Get a file content if it contains "Chut":

>>> grep_chut ='README.rst') | sh.grep('Chut')
>>> if grep_chut:
...     print(grep_chut | sh.head("-n1"))

Redirect output to a file:

>>> ret = (grep_chut | sh.head("-n1")) > '/tmp/chut.txt'
>>> ret.succeeded
>>> print('/tmp/chut.txt'))

Or to stdout:

>>>'/tmp/chut.txt') > 1  # doctest: +SKIP

Redirect stdout to stderr:

>>>'/tmp/chut.txt') > 2  # doctest: +SKIP

Run many command with a pool of processes:

>>> [ret.succeeded for ret in['.', ['-l', '/tmp']])]
[True, True]

Use docopt to write a console script. This script will take an iface as argument and return a code 1 if no address is found:

>>> @sh.console_script
... def got_inet_addr(args):
...     """Usage: got_inet_addr <iface>"""
...     if sh.ifconfig(args['<iface>']) | sh.grep('inet addr:'):
...         return 1