shshsh 🐍❤️🐚
Shshsh is a bridge connects python and shell.
- A simple way to write shell commands in Python.
- Flexibility.
- Support for directly chaining a Python function in a pipeline.
Installation
To install shshsh with pip, run: pip install shshsh
To install shshsh with conda, run: conda install shshsh -c conda-forge
To install shshsh from source, clone the repository and run: pip install poetry;poetry install
⚠️ If you are using python3.8: Be very careful with python function Pipe, there are known bugs!
Basic Usage
You can use I >> "[command]" or Sh("[command]")in any Python project.
Here's an example of getting all file which name contains "test":
from shshsh import I, IZ
for filename in I >> "ls" | "grep test":
print(filename)
# zero mode, split line by "\x00"
for filename in IZ >> "ls" | "grep test":
print(filename)
Also, you can safely pass parameter without worrying about command injection; shshsh will help you escape all bash control characters:
from shshsh import I
from sys import stdout
res = (I >> "echo #{}") % "dangerous; cat /etc/passwd" | stdout
res.wait()
# dangerous; cat /etc/passwd
To operate on the current working directory (cwd):
from shshsh.utils import cwd
# change dir
after_change_path = cwd("../../")
# to get current cwd, just don't give any parameter
cwd()
Python functions or iterables can be part of the chain. You no longer have to search Google (or chatgpt) repeatedly to write sed or awk 😇:
from shshsh import I
from sys import stdout
# as map function
def add_suffix(line: str) -> str:
return line + ".py"
res = I >> "ls -alh" | add_suffix | "grep test" | stdout
res.wait()
# as data source
def data_source():
for i in range(10):
yield f"test{i}"
res = I >> data_source() | "grep test1" | stdout
res.wait()
By default, stderr will directly redirect to current Python process's stderr.
But you can also keep its result using the redirect expr >= for stderr and > for stdout:
from shshsh import I, keep
res = I >> "ls not_exist" >= keep
res.wait()
print(res.stderr.read())
The redirect expression can redirect the stream to any kind of IO object:
from shshsh import I
with open("res", "w") as f:
# redirect stdout to file.
res = I >> "echo 123" > f
# redirect stderr to file.
res1 = I >> "ls not_exist" >= f
res1.wait()
res.wait()
Metadata
Release files for shshsh 1.0.6
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 | |
|---|---|---|---|---|
| shshsh-1.0.6.tar.gz | 9.5 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| shshsh-1.0.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 20.1 kB
Release files / shshsh-1.0.6.tar.gz
| Download URL | shshsh-1.0.6.tar.gz |
|---|---|
| Size | 9.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
991810b105de9c54c81c5dc77fab0a9fe0c2ba54ec1a0e64c5d5f8c9941c2da6
|
|
BLAKE2b-256 checksum How to use checksums |
e52dcfbac8366f103ff1f4b9400b977bdc70d9d22f6b93065c4a3ba7b3205c33
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.2 CPython/3.11.8 Linux/6.7.8-arch1-1
|
Release files / shshsh-1.0.6-py3-none-any.whl
| Download URL | shshsh-1.0.6-py3-none-any.whl |
|---|---|
| Size | 10.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
93cd27586803a60f195131e6c4df66231a590187371a9ec8dc6a8ec9dadc6ea8
|
|
BLAKE2b-256 checksum How to use checksums |
49358b72ca643a220041e4ccfda16099335f7d45798b5e55719cc461671fd2f3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.8.2 CPython/3.11.8 Linux/6.7.8-arch1-1
|
Security for shshsh 1.0.6
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.