A tool for writing shell scripts in python.
Project description
prey
#!/usr/bin/env prey
async def main():
await x("cat pyproject.toml | grep name")
branch = await x("git branch --show-current")
await x(f"dep deploy --branch={branch}")
await x(
[
"sleep 1; echo 1",
"sleep 2; echo 2",
"sleep 3; echo 3",
]
)
name = "foo bar"
await x(f"mkdir /tmp/${name}")
A tool for writing shell scripts in Python. Inspired by google/zx. This package provides a wrapper around asyncio.subprocess
. If you're looking for a more complete solution you may want to check out zxpy.
Install
pip install prey
Documentation
Wrap your scripts in an async function called main
:
async def main():
# script...
It must be called main
as the executable looks for a function calls main and calls it. This is used so commands can be asynchronous.
You can add the shebang at the top of your script:
#!/usr/bin/env prey
and run it like so:
chmod +x ./script.py
./script.py
Or via the prey
executable:
prey ./script.py
When using prey
via the executable or a shebang, all of the functions (x
, colorama
, request
, etc) are available wihtout any imports.
await x("command")
Asychronously executes a given string using the create_subprocess_shell
function from the asyncio.subprocess
module and returns the output.
count = int(await x("ls -1 | wc -l"))
print(f"Files count: {count}")
cd("filepath")
Changes the current working directory.
cd("/tmp")
await x('pwd') # outputs /tmp
colorama package
The colorama package is available without importing inside scripts.
print(f"{colorama.Fore.BLUE}Hello World!")
request package
A wrapper around aiohttp, aiohttp-requests.requests.session.request
, is available without importing inside scripts.
response = await request("get", "http://python.org")
html = await response.text()
Importing from other scripts
It is possible to make use of x
and other functions via explicit imports:
#!/usr/bin/env prey
from prey import x
await x('date')
Passing env variables
os.environ["FOO"] = "bar"
await x('echo $FOO')
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
File details
Details for the file prey-0.1.4.tar.gz
.
File metadata
- Download URL: prey-0.1.4.tar.gz
- Upload date:
- Size: 4.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.6 CPython/3.9.5 Linux/5.8.0-55-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6cbf262a861755f1dbee4433e2af857b0a449cc25cacb790635daa2728f2e005 |
|
MD5 | a270465032fbb57c964e9f09d64af3ce |
|
BLAKE2b-256 | 9fe8d7994dd71197b5967bd01b6509471e58911fbf26515c9a4d3e119a3cd3d0 |
File details
Details for the file prey-0.1.4-py3-none-any.whl
.
File metadata
- Download URL: prey-0.1.4-py3-none-any.whl
- Upload date:
- Size: 4.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.1.6 CPython/3.9.5 Linux/5.8.0-55-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 44f05f079e02e61e9dcc97272715db4dc6a5bf7637bd3e979ae4007945c241e0 |
|
MD5 | 0a302b30d58b0a12f041dcf1a27acf08 |
|
BLAKE2b-256 | 40a5f5115ea1abfbf008271455c9aba4c2ccca0e0e96c626602b3a5f0b0833b6 |