Pyash
Hate shell scripting? Love Python! Meet the horrible Frankenstein of the two!
Pyash takes the best part of shell scripting, the ability to stream data through great chains of shell programs, and adds that ability to Python. In the process it retains the same familiar syntax but in a more Pythonic form!
from pyash import cat, grep
cat(".gitignore") | grep("env") > "out.txt"
Importing Shell Programs
Importing shell programs is as easy as
from pyash import grep, find, bash
Pyash automatically searches your PATH variable and loads any executable programs it finds, making them available through import.
Try to avoid importing * as you'll find basic builtin functions like print() suddenly don't work!
Running Shell Programs
Once you've imported the programs you want to import you can use them as you would any normal Python function splitting arguments or keeping them all together as you want:
print(grep("-i", "-r", "env", "."))
print(grep("-i -r env ."))
It's important to note that all programs are lazy evaluated, i.e. a program only runs when Pyash knows where data is going.
For example, the above grep commands will only execute when you print their output.
That means that if you don't care about the output you'll need to make sure you call run() to make the program execute:
kubectl("delete", "pod", "my-pod").run()
Piping Data
Data can be piped between, to and from files using the same syntax you use in shell scripts:
print(kubectl("get", "pods") | grep("postgres"))
echo("I'm a pretty butterfly") > butterfly.txt
echo("Flutter! Flutter! Flutter!") >> butterfly.txt
(docker("container", "stop") < "my_containers.txt").run()
Note that when you start piping a program's output somewhere else it begins execution, so the 2nd and 3rd examples don't need you to call run().
If you need to both pipe in from a file and out from a file you need to place parentheses around the pipe in, this just seems to be a limitation of our abuse of Python.
(cat() | grep("env") < ".gitignore") > "myfile.txt"
Release files for pyash 0.1.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 | |
|---|---|---|---|
| pyash-0.1.0.tar.gz | 3.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pyash-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 9.2 kB
Release files / pyash-0.1.0.tar.gz
| Download URL | pyash-0.1.0.tar.gz |
|---|---|
| Size | 3.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8d512e064940eac34d00b92012a9f7ec6a5950e7053b6d9e86ee4c6673f078d4
|
|
BLAKE2b-256 checksum How to use checksums |
6e220ac129c99c8608479fae2159541261e62a0d97d9952dc1cdffcb6b8f56f5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.1
|
Release files / pyash-0.1.0-py3-none-any.whl
| Download URL | pyash-0.1.0-py3-none-any.whl |
|---|---|
| Size | 5.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
aaab0d1dcd55619aec431ad0cbb7d8c5c3836c5b21c13fd2fcc608981ab4325e
|
|
BLAKE2b-256 checksum How to use checksums |
e8ee15efafa38d14faaf07a94efbca1226022aff68b851556ef2cb386583725d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/44.0.0 requests-toolbelt/0.9.1 tqdm/4.41.1 CPython/3.7.1
|