Skip to main content
Help the Python Software Foundation raise $60,000 USD by December 31st!  Building the PSF Q4 Fundraiser

shell command invocation with backquotes, like Perl, Ruby.

Project description


backquotes brings (Perl / Ruby)’s shell invocation syntax to Python.

backquotes is experimental module by now, using it in a serious program is not recommended.


Firstly, remember to import backquotes module.

import backquotes


You can use similar syntax to Perl / Ruby.

import backquotes

Pipes and redirections

Yes, you can use pipes, redirections too.

import backquotes
print(`ls | tr [a-z] [A-Z]`.splitlines())

Local variables substitution

To bring local variables in Python code to shell command, use Perl-like variables substitution.

import backquotes
spam = 'spam'
print(`echo $spam`)

$$ is substituted to a literal $.

import backquotes
print(`echo $$PATH`)



You can use runtime-preprocessing only in Python 2. This works transparently when you import backquotes.


Python 3 raises SyntaxError on a backquote character before evaluate the first line. So you CANNOT use runtime-preprocessing.

#!/usr/bin/env python
import backquotes

Save as, and run it as usual.


You will see the result of date command.

Runtime-preprocessing sometimes causes SyntaxError before preprocessing starts, especially with complex commands invocation. You can avoid this error by using single-quotes just inside the backquotes.

print(`'for file in *; do echo $file; done'`)

Execute backquotes module

Run python with -m backquotes option to invoke backquotes as a script. backquotes compiles a plain Python code and execute it.


This works both in Python 2 / 3.

python -m backquotes

You can pass arguments to the script.

python -m backquotes 2015 10 31

Preprocess Python code

Run python with -m backquotes -E option to only preprocess the given source file and print to stdout.


Preprocessed python code is almost the same as the original code semantically, but whitespaces are moved by the preprocessor.


This works both in Python 2 / 3.

mkdir dist
python -m backquotes -E > dist/
python dist/


  • backquotes does not work in Python REPL. Import it in REPL causes warnings.
  • a module which imports backquotes does not work when it is imported.


pip install backquotes


git clone
cd backquotes
python install



Project details

Download files

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

Files for backquotes, version 0.0.3
Filename, size File type Python version Upload date Hashes
Filename, size backquotes-0.0.3-py2-none-any.whl (6.7 kB) File type Wheel Python version 2.6 Upload date Hashes View
Filename, size backquotes-0.0.3.tar.gz (6.8 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page