MiteSh
is a very simple wrapper over
subprocess :) . It
enables us to run any POSIX shell (one-liner) in python and provides
output line by line through generator. This is inspired by perl's
backtick operator ``.
MiteSh
is:
- tiny: The current source code has 164 lines of code (with about 35% documentation) and 114 lines of test.
- written in pure Python: MiteSh neither needs an external server nor any dependencies from PyPI.
- works on Python 3.6+ and PyPy3: MiteSh works on all modern versions of Python and PyPy.
- powerfully extensible: You can easily extend
MiteSh
to more shells, currently tested with- sh
- bash
- zsh
MiteSh has been tested with Python 3.6+ and PyPy3.
MiteSh
should run on all *NIX Operating Systems. Like:
- GNU/Linux
- UNIX *BSD
- Mac OS (Darwin)
More examples can be found in
tests/test_mitesh.py
>>> from mitesh import MiteSh
>>> for line in MiteSh("echo Hello World").execute():
... print(line)
...
Hello World
>>> for line in MiteSh("cat /proc/cpuinfo | grep \"cpu cores\" | uniq | cut -d: -f2 | sed 's/ //g'").execute():
... print(line)
...
6
The above command was run on Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz
>>> for line in MiteSh("echo hello", sh_type="sh").execute():
... print(line)
...
hello
>>> for line in MiteSh("ps", sh_type="sh").execute():
... print(line)
...
PID TTY TIME CMD
51839 pts/5 00:00:00 bash
91559 pts/5 00:00:00 python3
102811 pts/5 00:00:00 sh
102812 pts/5 00:00:00 ps
>>> for line in MiteSh("ps", sh_type="zsh").execute():
... print(line)
...
PID TTY TIME CMD
51839 pts/5 00:00:00 bash
91559 pts/5 00:00:00 python3
103035 pts/5 00:00:00 zsh
103036 pts/5 00:00:00 ps
$ python3 -m unittest tests/test_mitesh.py
...........
----------------------------------------------------------------------
Ran 11 tests in 0.038s
OK
I would like to dedicate this package to my Mentor CNB and my Friend Venkatesh Pitta, without their inspiration and support, this would not be possible. Also, I would like to thank God, my Teachers, my Parents, my Wife and Daughter to stand with me all the times.
Whether reporting bugs, discussing improvements and new ideas or writing
extensions: Contributions to MiteSh
are welcome! Here's how to get
started:
- Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug
- Fork the repository on
Github, create a new branch off the
master
branch and start making your changes (known as GitHub Flow) - Write a test which shows that the bug was fixed or that the feature works as expected
- Send a pull request and bug the maintainer until it gets merged and published