Skip to main content

Shell scripting library for Python

Project description

pyscripting is python module that provides various utilities to make shell scripting with python easier.

Getting started

  1. Get

    pip install pyscripting
  2. Create your python shell script

    #!/usr/bin/env python
    from scripting import sh'-l')
  3. Use your script:

    chmod +x

Calling external commands

There are three ways to call external commands.

If possible, python replacement of an external command will be used. Replacements will not be used only in direct calling.

For all replaced commands see Replaced commands.

Direct calling

Returns exit code.

sh('ls', '-l')

Indirect calling

Returns exit code.'-l')

Call and return output

Returns stripped stdout (stderr will not be included).

Using this method, output of command will not be printed to stdout. Before returning output, leading white spaces will be stripped.

Don’t use this methos for large outputs.

output = sh.get('ls', '-l')
print('Output was: %s' % output)

Argument handling

You can access arguments passed to script using argv property:

sh.argv[0] - called script name
sh.argv[1] - first argument

Replaced commands

To avoid overhead and for simplicity reasons, some external commands was replaced by python’s internal functions, which works much faster, that calling external command.


Same as external basename.

Returns string.


Same as external exit.


Similar to external find command.

Returns iterator of all found files.

Example usage:

for f in sh.find(type='f', exclude=['*.pyc']):

Same as external mkdir.


Same as external mkdir -p.


Similar to external test.

Returns boolean.

Example usage:

if sh.test('-d', '/tmp'):
    print('/tmp is directory.')

Makefile functionality

Example (

#!/usr/bin/env python

from scripting import sh, Makefile

make = Makefile(sh)

def myrule(target):

def main(target):

Last line checks sys.argv and executes specified rule or default if no particular rule is specified. myrule will be executed only, if target file /tmp/myfile.txt does not exists.:


Now call particular rule:

./ myrule

Project details

Release history Release notifications | RSS feed

This version


Download files

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

Source Distribution

pyscripting-0.1.tar.gz (3.6 kB view hashes)

Uploaded source

Built Distribution

pyscripting-0.1.linux-x86_64.exe (68.1 kB view hashes)

Uploaded any

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