Pysh
About
Pysh aims at providing the tools required to write in Python the script I would have written in bash before.
Python provide a more robust, and more powerful environment for scripting and makes the script easier to maintain and extend. Pysh makes it possible to write file manipulation script just as quickly as in bash.
It should be good both for quick one-of scripts, as well as more complex reusable small programs.
Installation
Be careful: the pysh name was already taken on PyPI, it is a different package, that I have nothing to do with.
My package is named tc-pysh
pip install tc-pysh
Usage
At the center of pysh is the path facilities: tc_pysh.AbsolutePath and tc_pysh.RelativePath are objects representing locations in the file system taht are easy to manipulate and use with pysh utils, as well as with most of python standard library thanks to os.PathLike.
tc_pysh.utils provides equivalents of the commonly used commands in bash scripts such as mv, cp, rm, cat, etc.
tc_pysh.ls and tc_pysh.find provides familiar interface to the tc_pysh.query facilities, making it easy to browse a directory or arborescence, with tools likes sorting and filtering in the form of iterators, building on top of the standard library and the re standard module.
tc_pysh.file provides a set of functions that are related to file content, like grep, head and tail.
Here is an example of using ls to print the sizes of all text files of a directory.
from tc_pysh import ls
from tc_pysh.file import size, human
for f in ls().name(r".*\.txt").sort():
s = size(f)
s, u = human(s)
print(str(f), s, u)
Commands like ls return a tc_pysh.stream.Stream object, an iterable that
is designed to chain sequence operators such as .map and .filter.
tc_pysh.script_utils provide convenient wrappers around the builtin
argparse module that helps with generating CLI in a pythonic way.
from tc_pysh import ls
from tc_pysh.file import size, human
from tc_pysh.script_utils import script, optional, positional
@script(
positional("pat", help="Pattern to math against file names."),
optional("root", default=".", help="Where to list files."),
)
def pls(opts):
"List files matching PAT in ROOT."
for f in ls(opts.root).name(opts.pat).sort():
s = size(f)
s, u = human(s)
print(str(f), s, u + "B")
if __name__ == "__main__":
pls() # automatically parses sys.argv (but you can also explicitly pass the script)
Metadata
Release files for tc-pysh 0.9.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| tc_pysh-0.9.0.tar.gz | 16.0 kB | Without provenance | Details for tc_pysh-0.9.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tc_pysh-0.9.0-py2.py3-none-any.whl | Python 2, Python 3 | none | any | Details for tc_pysh-0.9.0-py2.py3-none-any.whl |
Total release size: 36.6 kB
Release files / tc_pysh-0.9.0.tar.gz
| Download URL | tc_pysh-0.9.0.tar.gz |
|---|---|
| Size | 16.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
73803760f6c9e02996e95bdccfd80acd1dc5c19462879154691087d11c4b57c1
|
|
BLAKE2b-256 checksum How to use checksums |
2c03f946e805332335c2e8cf47f6ad5402c4fbe09759c5204c2058e74f881524
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.27.2
|
Release files / tc_pysh-0.9.0-py2.py3-none-any.whl
| Download URL | tc_pysh-0.9.0-py2.py3-none-any.whl |
|---|---|
| Size | 20.6 kB |
| Tags | Python 2 Python 3 |
|
SHA-256 checksum How to use checksums |
0ef43f11f59c7c36a970bfbc0289ed88e8ce188321a9f12ac36a8d37741f8033
|
|
BLAKE2b-256 checksum How to use checksums |
64e469ede99ef06606d0abcd497387b3e45e9150683ed1b7463d62d7c97214c9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
python-httpx/0.27.2
|
Security for tc-pysh 0.9.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.