Skip to main content

Modestly Integrated To Every SHell

Project description

Introduction

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

Supported Python Versions

MiteSh has been tested with Python 3.6+ and PyPy3.

Supported Operating Systems

MiteSh should run on all *NIX Operating Systems. Like:

  • GNU/Linux

  • UNIX *BSD

  • Mac OS (Darwin)

Examples

More examples can be found in tests/test_mitesh.py

Run Hello World

>>> from mitesh import MiteSh
>>> for line in MiteSh("echo Hello World").execute():
...     print(line)
...
Hello World

Get Number of CPU Cores in Linux

>>> 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

Using Different Shell

>>> 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

Tests

$ python3 -m unittest tests/test_mitesh.py
...........
----------------------------------------------------------------------
Ran 11 tests in 0.038s

OK

Acknowledgement

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.

Contributing

Whether reporting bugs, discussing improvements and new ideas or writing extensions: Contributions to MiteSh are welcome! Here’s how to get started:

  1. Check for open issues or open a fresh issue to start a discussion around a feature idea or a bug

  2. Fork the repository on Github, create a new branch off the master branch and start making your changes (known as GitHub Flow)

  3. Write a test which shows that the bug was fixed or that the feature works as expected

  4. Send a pull request and bug the maintainer until it gets merged and published

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mitesh-0.0.0.tar.gz (10.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mitesh-0.0.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file mitesh-0.0.0.tar.gz.

File metadata

  • Download URL: mitesh-0.0.0.tar.gz
  • Upload date:
  • Size: 10.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.6

File hashes

Hashes for mitesh-0.0.0.tar.gz
Algorithm Hash digest
SHA256 092eb46ba932480fc500379fff2528ada9dbbdb3ec8f0714c8184b2959dc4b80
MD5 d38e87a529a03d3faa7c5b7225ebe695
BLAKE2b-256 12a2fd98ce0078d68b3c9d9fdae09f07aaefdc72a6c1e58d3dfe03f6d779f514

See more details on using hashes here.

File details

Details for the file mitesh-0.0.0-py3-none-any.whl.

File metadata

  • Download URL: mitesh-0.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.8.6

File hashes

Hashes for mitesh-0.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 71ec9e73d63800f66caa1a1d554c1eac7badd52ed27ebc8928b3e6c25eec1486
MD5 c30ca1c02d64dd6948dec98204e07dbf
BLAKE2b-256 d453ce2f54adcdf46728978d97378a595078e8ec228dd81420b4f16fae02ae0e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page