pype: command-line pipes in Python
Usage
At the command prompt, use pype to act on each item in the file with python commands:
$ printf 'abc' | pype str.upper ABC
Chain python functions together with !:
$ printf 'Hello' | pype 'str.upper ! len' 5
Use ? as a placeholder for the input at each stage:
$ printf 'Hello World' | pype 'str.split ! ?[0].upper() + "!"'
HELLO!
$ printf 'Hello World' | pype 'str.split ! ?[0].upper() + "!" ! ?.replace("H", "J")'
JELLO!
Given a server responding to http://localhost:8080/ and a list of urls in urls.txt :
http://localhost:8080/Requester_254 http://localhost:8080/Requester_083 http://localhost:8080/Requester_128 http://localhost:8080/Requester_064 http://localhost:8080/Requester_276
Automatically import required modules and use their functions:
$ pype 'str.strip ! requests.get ! ?.text ' < urls.txt Hello, Requester_254. You are client number 7903 for this server. Hello, Requester_083. You are client number 7904 for this server. Hello, Requester_128. You are client number 7905 for this server. Hello, Requester_064. You are client number 7906 for this server. Hello, Requester_276. You are client number 7907 for this server.
Use map to act on each input item (map is the default command). Use apply to act on the sequence of items. Finding the largest number returned from the server:
$ pype --newlines=no map 'str.strip ! requests.get ! ?.text ! ?.split()[6] ! int' apply 'max' < urls.txt 7933
Making sequential requests is slow. Use --async to make I/O really fast (see caveats below).
$ time pype 'str.strip ! requests.get ! ?.text' < urls.txt Hello, Requester_254. You are client number 8061 for this server. Hello, Requester_083. You are client number 8062 for this server. Hello, Requester_128. You are client number 8063 for this server. Hello, Requester_064. You are client number 8064 for this server. Hello, Requester_276. You are client number 8065 for this server. real 0m10.640s user 0m0.548s sys 0m0.022s
Making concurrent requests is much faster:
$ time pype --async 'str.strip ! treq.get ! treq.text_content' < urls.txt Hello, Requester_254. You are client number 8025 for this server. Hello, Requester_083. You are client number 8025 for this server. Hello, Requester_128. You are client number 8025 for this server. Hello, Requester_064. You are client number 8025 for this server. Hello, Requester_276. You are client number 8025 for this server. real 0m2.626s user 0m0.574s sys 0m0.044s
Installation
TBD
Caveats
pype assumes trusted command arguments and untrusted input stream data. It uses eval on your arguments, not on the input stream data. If you use exec, eval, subprocess, or similar commands, you can execute arbitrary code from the input stream.
--async currently works only with map, not apply and works only for a single map pipe-string, e.g. map 'str.upper ! len ! ? & 1', not for chains, e.g. map str.upper map len map '? & 1'.
Status
Check the issues page for open tickets
This package is experimental pre-alpha and is subject to change.
Metadata
Release files for thru 0.0.27
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| thru-0.0.27.tar.gz | 8.1 kB | Without provenance | Details for thru-0.0.27.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| thru-0.0.27-py3-none-any.whl | Python 3 | none | any | Details for thru-0.0.27-py3-none-any.whl |
Total release size: 15.6 kB
Release files / thru-0.0.27.tar.gz
| Download URL | thru-0.0.27.tar.gz |
|---|---|
| Size | 8.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
0f39b191a8a3208184b83ebde6005d6cb465c0e57f352a6195f430aceeb25c88
|
|
BLAKE2b-256 checksum How to use checksums |
c73014374744e03d83c8fc6602188860c6fa04fc645ff2b2576f2e628f6447b5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.3
|
Release files / thru-0.0.27-py3-none-any.whl
| Download URL | thru-0.0.27-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
eb7d6348ecf2fa8448de4c15f3d62cf25b26f0adc7583e9acf9fa9e74dca135f
|
|
BLAKE2b-256 checksum How to use checksums |
fb6b1e5167614a9f7ac80089a9dbc494c90a2485075c1e397681a732778482a2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/39.0.1 requests-toolbelt/0.8.0 tqdm/4.26.0 CPython/3.6.3
|
Security for thru 0.0.27
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.