Skip to main content

Python Shell Wrapper library

Project description

Python Shell Wrapper Library

A flexible, easy-to-use library to integrate your Python script with Unix ecosystems.

Why yet another one?

This library comes with a few major points to use it:

  • It is easy and intuitive (see examples)
  • It's compatible with Python 2 (can be useful in old large systems)
  • Continuous support of the library

Getting started

This library is pretty easy to use:

from python_shell import Shell

Shell.ls('-l', '$HOME')  # Equals "ls -l $HOME"

command = Shell.whoami()  # Equals "whoami"
print(command.output)  # prints your current user name
print(command)  # Does the same as above

print(command.command)  # prints "whoami"
print(repr(command))  # Does the same as above

print(command.errors)  # prints text string from stderr
print(command.return_code)  # prints "0"
print(command.arguments)  # prints ""

To run any Bash command, you need to do it like this:

Shell.<bash_command_name>(<bash command parameters>)

For example, you want to create a new folder:

Shell.mkdir('-p', '/tmp/new_folder')

It's also possible to run a command which name is not a valid Python identifier. To do this, use Shell class as a callable instance:

command = Shell('2to3')

When the command fails (returncode is non-zero), Shell throws a ShellException error. However, even if you didn't save a reference to your command, you still can access it. To do this, try

last_cmd = Shell.last_command

Installing

Simply run

pip install python-shell

Integration with development tools

Shell class now allows to list all available commands simply by

dir(Shell)

This feature enables autocomplete of commands in a few popular interfaces:

  • BPython
  • IPython

Extending the basic functionality

It's possible to extend the existing functionality without forking the project. The library provides an interface to add a custom Command class.

Running the tests

This library contains tests written using unittest module, so just run in the project directory

python -m unittest

Also it's possible to run tests using Tox:

tox -e <env>

Supported environments:

  • py27
  • py35
  • py36
  • py37
  • py38
  • coverage (using Python 3)
  • coverage (using Python 2.7)
  • pep8 (style checking)

Other old versions of Python (e.g. 2.6, 3.4, etc) will never be supported. However, you always can implement such support in your forks.

Test coverage is one of the top priority for this library:

  • Coverage using Python 2.7: 96%
  • Coverage using Python 3.x: 92%

Authors

Contacts

License

This project is licensed under the MIT License - see the LICENSE.md file for details.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_shell-1.0.2-py2.py3-none-any.whl (20.9 kB view details)

Uploaded Python 2Python 3

File details

Details for the file python_shell-1.0.2-py2.py3-none-any.whl.

File metadata

  • Download URL: python_shell-1.0.2-py2.py3-none-any.whl
  • Upload date:
  • Size: 20.9 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.2.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.9

File hashes

Hashes for python_shell-1.0.2-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 23d3368f79bb0ced312cef9cd83724f2629399e71095ea5d75cfc111a9cc1271
MD5 46cc7690f7140a02b7e478a31ac9e843
BLAKE2b-256 8055deb51c025bdc53d26ab7a99c31c03f56a52b94314e06d88206da6230a1ad

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page