Skip to main content

shshsh 🐍❤️🐚

PyPI

Shshsh is a bridge connects python and shell.

  • A simple way to write shell in python.
  • Flexable.
  • Support directly chain a python function in pipe.

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

for filename in I >> "ls" | "grep test":
    print(filename)

Also, you can safely pass parameter without command injection, shshsh will help you escape all bash control character:

from shshsh import I
from sys import stdout

res = (I >> "echo #{}") % "dangerous; cat /etc/passwd" | stdout
res.wait()
# dangerous; cat /etc/passwd

The way to operate cwd:

from shshsh.utils import cwd

# change dir
after_change_path = cwd("../../")

# to get current cwd, just don't give any parameter
cwd()

Python function or iterable can be part of 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, the stderr will directly redirect to current python process's stderr.

But you can also keep its result by 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 expr 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.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for shshsh 1.0.4
File Size Uploaded
shshsh-1.0.4.tar.gz 8.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for shshsh 1.0.4
File Interpreter ABI Platform
shshsh-1.0.4-py3-none-any.whl Python 3 none any Details

Total release size: 17.9 kB

Release files / shshsh-1.0.4.tar.gz

Download URL shshsh-1.0.4.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
ea87cb39e925bb3ae757a78e299c563b4a6579334e8a12e76cafe5c51c2e9d7b
BLAKE2b-256 checksum
How to use checksums
022f5026d465fec9c9c7155b09e54e8a523ed74042d63bc0d10a7bad30f266aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.9.13 Linux/6.4.6-arch1-1

Release files / shshsh-1.0.4-py3-none-any.whl

Download URL shshsh-1.0.4-py3-none-any.whl
Size 9.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
42ad7264a2b17363239a00111b8df18743fc6361f06c568f4c9c6d8abd516b48
BLAKE2b-256 checksum
How to use checksums
12d641e0abb49f89825f1a2c0a9e77e8fee3a2b8bc743ddbc7d2ac31730f7ada
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.5.1 CPython/3.9.13 Linux/6.4.6-arch1-1

Release history Release notifications | RSS feed

1.0.6

2 release files

1.0.5

2 release files

This release

1.0.4 This release

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page