Plumbum: shell combinators library
Project description
Ever wished the wrist-handiness of shell scripts be put into a real programming language? Say hello to Plumbum Shell Combinators. Plumbum (Latin for lead, which was used to create pipes back in the day) is a small yet feature-rich library for shell script-like programs in Python. The motto of the library is “Never write shell scripts again”, and thus it attempts to mimic the shell syntax (“shell combinators”) where it makes sense, while keeping it all pythonic and cross-platform.
Apart from shell-like syntax and handy shortcuts, the library provides local and remote command execution (over SSH), local and remote file-system paths, easy working-directory and environment manipulation, and a programmatic Command-Line Interface (CLI) application toolkit. Now let’s see some code!
This is only a teaser; the full documentation can be found at Read the Docs
Cheat Sheet
Basics
>>> from plumbum import local, FG, BG >>> from plumbum.cmd import ls, grep, wc, cat, head >>> ls LocalCommand(<LocalPath /bin/ls>) >>> ls() u'build.py\ndist\ndocs\nLICENSE\nplumbum\nREADME.rst\nsetup.py\ntests\ntodo.txt\n'
Piping
>>> chain = ls["-a"] | grep["-v", "\\.py"] | wc["-l"] >>> print chain /bin/ls -a | /bin/grep -v '\.py' | /usr/bin/wc -l >>> chain() u'13\n'
Redirection
>>> ((cat < "setup.py") | head["-n", 4])() u'#!/usr/bin/env python\nimport os\n\ntry:\n' >>> (ls["-a"] > "file.list")() u'' >>> (cat["file.list"] | wc["-l"])() u'17\n'
Working-directory manipulation
>>> local.cwd <Workdir /home/tomer/workspace/plumbum> >>> with local.cwd(local.cwd / "docs"): ... chain() ... u'15\n'
Foreground and background execution
>>> (ls["-a"] | grep["\\.py"]) & FG # The output is printed to stdout directly build.py .pydevproject setup.py >>> (ls["-a"] | grep["\\.py"]) & BG # The process runs "in the background" <Future ['/bin/grep', '\\.py'] (running)>
Command nesting
>>> from plumbum.cmd import sudo >>> print sudo[ifconfig["-a"]] /usr/bin/sudo /sbin/ifconfig -a >>> (sudo[ifconfig["-a"]] | grep["-i", "loop"]) & FG lo Link encap:Local Loopback UP LOOPBACK RUNNING MTU:16436 Metric:1
Remote commands (over SSH)
>>> from plumbum import SshMachine >>> remote = SshMachine("your-host.com") >>> r_ls = remote["ls"] >>> with remote.cwd("/lib"): ... (r_ls | grep["0.so.0"])() ... u'libusb-1.0.so.0\nlibusb-1.0.so.0.0.0\n'
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file plumbum-0.9.0.zip
.
File metadata
- Download URL: plumbum-0.9.0.zip
- Upload date:
- Size: 35.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | efb6612b3d62e33a6672a3f198df4b8b202448414ed806c121c71c35c237fe02 |
|
MD5 | 46e1cc107255ca4d5d80f90f2d218c0e |
|
BLAKE2b-256 | 77aec1e49dcdf6ec15249e82ca2e9d21d83c119cae7c6e27e026cbcfef38007d |
File details
Details for the file plumbum-0.9.0.tar.gz
.
File metadata
- Download URL: plumbum-0.9.0.tar.gz
- Upload date:
- Size: 28.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5d049c44dcfa0aedd6077f4512eb8216722ae791bf92623e52e07bf82a76d691 |
|
MD5 | 3d26aaca527b3bb1a01e25f63a442d8a |
|
BLAKE2b-256 | d446cb4744071038a0be2b3b00b0ff91a0ae1956340eb5203518b9beb0ccfa08 |
File details
Details for the file plumbum-0.9.0.win32.exe
.
File metadata
- Download URL: plumbum-0.9.0.win32.exe
- Upload date:
- Size: 230.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 469b294c5806c40c49ba94e3ed2adede90d712f3916ce085bad90a0ed41711be |
|
MD5 | ab347c45f4295b250e49c1f4b146d016 |
|
BLAKE2b-256 | d377d3aeb92e62024f9ddb27d1f0ef9e03bcb5e0be7e4e9a74dd1816edaf47d1 |