Skip to main content

use python scripts in unix pipes

Project description

pypi pypi pypi

py-pepe

Super simple pipeline helper on Python. Works like awk but easier to remember (and also less posibilities...).

PEPE can work in 2 different ways:

1. As python module

Don't remember awk commands? Not a problem! Just insert python script here and read result of previous command using pepe.read(). Additionally, you can select N column (like column 6 in example):

# Show max usage RAM from process
ps ux | python -c "import pepe; x=pepe.read(6); print(max(x[1:]))"

2. As CLI

Don't want to call python scripts like that? We got you a CLI tool too!

CLI interface totally mimics python functions usage:

# Show total RAM usage of Visual Studio Code process
ps ux | grep "Visual Studio Code" | pepe sum 6

Here you add pepe sum 6 in pipe. That's identical to import pepe; pepe.sum(6). Same args and same positions. That's why if you want to sort lines as numbers, you need to add 0 positional arg: pepe sort 0 true, because that's identical to pepe.sort(0, True).

CLI doesn't have any flags, only positional args. That's for simplicity.

Installation

pip install py-pepe

Functions/Example of usage

help

To show help just call pepe command in terminal. Also on each error in input you probably will see pepe help.

pepe.read

Python-code only function (no cli). Reads all stdin and returns list of lines.

NOTE: This is the only function in pepe that returns a value. All other function just print their results.

Optional positional params: - <column> - select only N column

# Show max usage RAM from process
ps ux | python -c "import pepe; x=pepe.read(6); print(max(x[1:]))"

pepe.out

Display result. Works like cat or echo, but can select column.

Optional positional params: - <column> - select only N column

# Display only 1 column of ps ux
ps ux | head -n 10 | pepe out 1

# Same, but using python code
ps ux | head -n 10 | python -c "import pepe; pepe.out(1)"

# Without pepe
ps ux | head -n 10 | awk '{ print $1 }'

pepe.sum

Command sum allows to sum lines as numbers.

Optional positional params: - <column> - select only N column

Let's count RAM usage of all VSCode processes (on mac). Column 6 of "ps ux" output contains info about RAM:

# Select column 6 and sum
ps ux | grep "Visual Studio Code" | pepe sum 6

# Select column 6 using awk and sum all lines
ps ux | grep "Visual Studio Code" | awk '{ print $6 }' | pepe sum

# Same, but using python code
ps ux | grep "Visual Studio Code" | python -c "import pepe; pepe.sum(6)"

# Without pepe
ps ux | grep "Visual Studio Code" | awk '{sum+=$6} END {print sum}'

pepe.sort

pepe.min

pepe.max

pepe.size

pepe.count

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

py-pepe-0.0.5.tar.gz (5.8 kB view details)

Uploaded Source

Built Distribution

py_pepe-0.0.5-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file py-pepe-0.0.5.tar.gz.

File metadata

  • Download URL: py-pepe-0.0.5.tar.gz
  • Upload date:
  • Size: 5.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.13

File hashes

Hashes for py-pepe-0.0.5.tar.gz
Algorithm Hash digest
SHA256 580547c870feab08169a7f05476ddbd8cb752e0ba6fa9e2338293d473afb109a
MD5 52df333048090dd5a7da50e5faab7938
BLAKE2b-256 53709a4c83e30a4fc5fb561b7e93b55fd8c564127a8d0c865905d1e9514ba5fb

See more details on using hashes here.

File details

Details for the file py_pepe-0.0.5-py3-none-any.whl.

File metadata

  • Download URL: py_pepe-0.0.5-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.13

File hashes

Hashes for py_pepe-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 c4301f88a531bf28cd1dfe32dafe321e84261f4cd6aa387e28be89cbf92d9a1c
MD5 605b0c15a7c49fe33ef7bbb272cb970a
BLAKE2b-256 c22a84ff75793b1accc42fb6ee49d860c43f8882c03c9759a604ccc13ef9b7b0

See more details on using hashes here.

Supported by

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