No project description provided
Project description
[Normal]PyRunner
PyRunner allows you to run shell commands from Python in a way similar to how it is happening inside shell scripts
The following features apply:
- you don't think about separation of arguments and command; entire string is executed instead
- you don't think if command is built-in or external
- output of a command to either
stdoutorstderris printed into appropriate stream and visible to user (until muted) - called command is printed
- commands can be called with
sudoand the password for the current user will be asked once - entire script can be called with
sudoand the password, asked by sudo command, will be in effect - the result of a command can be grabbed, including
stdout,stderrand return code
The idea is to completely avoid boilerplate coding when writing shell automation scripts in Python.
Install from PyPI with pip install NormalPyRunner, then import pyrunner.
Examples
Importing library
>>> import pyrunner
Calling ls command
>>> _=pyrunner.exec("ls")
$ 'ls'
examples.py
__pycache__
pyrunner.py
README.md
setup.py
Note _= is used for Python REPL to suppress result printing.
Note command is printed with $ prefix.
Collecting command output as a whole string
>>> hostname=pyrunner.exec("hostname")
$ 'hostname'
myhost
>>> print(hostname)
myhost
Collecting command output as a list of strings
>>> files = []
>>> _=pyrunner.exec("ls", out_lines=files)
$ 'ls'
mnt
__pycache__
pyrunner.py
README.md
setup.py
>>> files
['mnt', '__pycache__', 'pyrunner.py', 'README.md', 'setup.py', '']
Suppressing printouts
>>> pyrunner.exec("ls", mute_out=True)
$ 'ls'
'mnt\n__pycache__\npyrunner.py\nREADME.md\nsetup.py'
Calling uname command with arguments
>>> _=pyrunner.exec("uname -a")
$ 'uname -a'
Linux myhostname 5.15.0-86-generic #96-Ubuntu SMP Wed Sep 20 08:23:49 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
Calling sudo command (mount)
>>> _=pyrunner.exec("mount /dev/loop46 mnt", sudo=True)
$ sudo mount /dev/loop46 mnt
[sudo] password for myuser:
mount: /home/myuser/mypath/pyrunner/mnt: WARNING: source write-protected, mounted read-only.
Note sudo=True is used to initiate sudo operations.
Note command is now prefixed with $ sudo
Checking mount is worked
>>> _=pyrunner.exec("ls mnt")
$ 'ls mnt'
bin
chromium.png
etc
firstrun
lib
man1
meta
snap
tests
usr
showing some image content.
Unmounting
>>> _=pyrunner.exec("umount mnt", sudo=True)
$ sudo umount mnt
Note password is not asked.
Security notes
Password is stored in Python variable. It is okay with standalone scripts, but can be not okay with interactive shells
like Jupyter. sudoers check is not supported yet.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file normalpyrunner-0.1.6.tar.gz.
File metadata
- Download URL: normalpyrunner-0.1.6.tar.gz
- Upload date:
- Size: 3.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
06a18bfa279b3654d729d8fea20a14b9c1ccbc216554d25579997b623e4fd98a
|
|
| MD5 |
13f5378603f51dece6a2233394382c03
|
|
| BLAKE2b-256 |
b664ff22aaffcd33755ea967a4ff4dd74b07847341b04c04a016ad96a58a2c2f
|
Provenance
The following attestation bundles were made for normalpyrunner-0.1.6.tar.gz:
Publisher:
publish-pypi.yml on dims12/PyRunner
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
normalpyrunner-0.1.6.tar.gz -
Subject digest:
06a18bfa279b3654d729d8fea20a14b9c1ccbc216554d25579997b623e4fd98a - Sigstore transparency entry: 1191351356
- Sigstore integration time:
-
Permalink:
dims12/PyRunner@8c414e0140dfa210d1e80671a563261c69724740 -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/dims12
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@8c414e0140dfa210d1e80671a563261c69724740 -
Trigger Event:
release
-
Statement type:
File details
Details for the file normalpyrunner-0.1.6-py3-none-any.whl.
File metadata
- Download URL: normalpyrunner-0.1.6-py3-none-any.whl
- Upload date:
- Size: 3.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
018c0913c1f95f4d5bf20df7ad7e5f840e9953e90efd9c1c405cc6a191908d80
|
|
| MD5 |
71f77aec1a05ad43101de0b9c209d0cf
|
|
| BLAKE2b-256 |
693e65e5f0ba609e5fb8dbb5b17876a81d16d398db0c05e7740d4f82be9408dc
|
Provenance
The following attestation bundles were made for normalpyrunner-0.1.6-py3-none-any.whl:
Publisher:
publish-pypi.yml on dims12/PyRunner
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
normalpyrunner-0.1.6-py3-none-any.whl -
Subject digest:
018c0913c1f95f4d5bf20df7ad7e5f840e9953e90efd9c1c405cc6a191908d80 - Sigstore transparency entry: 1191351357
- Sigstore integration time:
-
Permalink:
dims12/PyRunner@8c414e0140dfa210d1e80671a563261c69724740 -
Branch / Tag:
refs/tags/v0.1.6 - Owner: https://github.com/dims12
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-pypi.yml@8c414e0140dfa210d1e80671a563261c69724740 -
Trigger Event:
release
-
Statement type: