pshell: get rid of all bash scripts
Bash is widely regarded as a very poor choice to write any script longer than
a few lines. No auto-testing or auto-documentation support, bug-prone grammar,
and lack of debugging tools beyond echo make any substantial bash script
intrinsically fragile and hard to maintain.
Python on the other hand is a very robust language; however some operations
that could be performed in bash with a single line can take a disproportionate
amount of code when written in Python using os, shutil,
subprocess, etc.
pshell gets the best of both worlds by providing a unified, robust, and compact Python API to perform all the tasks that would be traditionally done through bash scripting.
To clarify: pshell is not an interactive shell; however nothing stops you from using it from your favourite python/ipython/jupyter terminal!
Some of the core features:
All actions are logged using the
loggingmodule. This is invaluable for auditing and debugging. It is strongly recommended to initialise the logging module and set the loglevel to INFO or DEBUG before invoking pshell.All file paths can contain bash-style environment variables, which are resolved on the fly. Failure to resolve an environment variable results in an
EnvironmentErrorbeing raised. You’re safe from the dreadedrm -rf $MISSPELLED/*!Functions from the core library are wrapped, hardened, polished, and occasionally changed to have a saner default behaviour.
Full
pathlibsupport, also when wrapping standard library functions that do not support it, such asshutilandglob.
Quick start
>>> import logging
>>> import pshell as sh
>>> logging.basicConfig(
... level=logging.INFO,
... format='%(asctime)s %(levelname)s [%(filename)s:%(lineno)d] %(message)s'
>>> )
>>> with sh.open("hello.txt", "w") as fh:
... fh.write("Hello world!")
2026-01-14 13:15:43,045 INFO [myscript.py:7] Opening 'hello.txt' for write
>>> sh.mkdir("somedir")
2026-01-14 13:16:08,503 INFO [myscript.py:9] Creating directory somedir
>>> sh.copy("hello.txt", "somedir/")
2026-01-14 13:16:30,468 INFO [myscript.py:10] Copying hello.txt to somedir/
Index
API Reference
Thread safety
pshell is fully thread safe and compatible with free-threading/noGIL interpreters. If thread safety is required, it is strongly recommended to use Python 3.14 or later; pshell does not work around bugs in earlier Python versions.
Credits
pshell was initially developed internally since 2014 as landg.bash by
Legal & General.
It was renamed and open-sourced in 2018.
License
This software is available under the open source Apache License.