Pype lets you run python on data as you pipe it around in your terminal.
To make a string upper case:
>> echo "python" | pype '_.upper()'
PYTHON
To get the last value in a comma separated list:
>> echo "1,2,3,4,5" | pype '_.split(",")[-1]'
5
If you need to import packages for your one-liner, just pass them using the -m
option.
We can use this to make GET requests on a list of URLs using requests
, doing something similar to what could be done with curl
and jq
.
cat links.txt | pype 'requests.get(_).json()["coord"]["lon"]' -m requests
If you want the variable that your input is called to be different than the default _
, you can rename it using -n
to make your one-liner easier to read.
cat links.txt | pype 'requests.get(link).json()["coord"]["lon"]' -m requests -n link
git clone https://github.com/ethan-homan/pype.git
cd pype
pip install .