Pypthon
Pipes for python3 to be used in shell
Setup
pip install pypthon -U
Usage
pyp 'Pypthon command'
If pypthon is not in your path, you must invoke via
python3 -m pypthon 'Pypthon command
To see the python code being generated, use the --show-python flag:
pyp --show-python 'Python command'
A Pypthon command consists of the following
source | piped function | piped function | piped function
The source must be any python expression. To have the source be an external command being piped into Pypthon, use stdin.
Piped functions
Piped functions are any python functions which take the previous value as their last argument. In the example pypthon code,
[2, 1, 3] | sorted | print "Sorted" "list:"
sorted takes in the iterable [2, 1, 3] as its last parameter and print takes the sorted list as its last parameter. When passing other arguments to functions in Pypthon, one must use the space separated syntax. In our example, the strings "Sorted" and "list:" are passed as arguments to print via the syntax of separating each argument with a space.
Sorted list: [1, 2, 3]
will be outputted by the above command.
Lambda expressions
In python, lambdas are of the following structure
lambda arg1, arg2: arg1 + arg2
In pypthon, lambda expressions do not need the lambda keyword before the arguments. In the example,
['1.', '6.', '2.', '4.'] | map x: int(float(x)) | reduce x, y: x if x > y else y | print
map converts the strings in the list into integers, and reduce finds the maximum of the integers.
Environment
The environment is fully customizable with a .pypthonrc.py. On startup, the pypthonrc will be imported, giving the pypthon command access to custom functions. If you feel like you have general functions that can be used by other pypthon users, do not hesitate to send a pull request to add your customizations to the standard environment as it is still growing. It is advisable to not include heavy imports such as numpy to the pypthonrc as the startup time will be negatively impacted for each invocation of pypthon.
To import modules specifically for the Pypthon invocation, use the -i flag.
pyp -i 'requests' -i 'numpy as np' "[1, 2, 3] | map x: requests.get('https://google.com').status_code | list | np.mean | print"
In the above example, numpy and requests were imported. The syntax of module as alias is valid in Pypthon. The methods in the modules are available for use in Pypthon.
The documentation for the standard environment is at docs/example.md.
Other
There are currently some bugs in parsing the source to the pipe chain. If it incorrectly raises an error in the first pipe segment, surround it with parenthesis and see if it works.
This project idea was heavily inspired by the pied piper package which only works with Python 2 and has virtually disappeared.
Metadata
Release files for pypthon 0.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| pypthon-0.3.2.tar.gz | 6.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pypthon-0.3.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 26.4 kB
Release files / pypthon-0.3.2.tar.gz
| Download URL | pypthon-0.3.2.tar.gz |
|---|---|
| Size | 6.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
df3245c2e9676288c338069c8144d2b45add42b8c294708edf9b4e86eca0077e
|
|
BLAKE2b-256 checksum How to use checksums |
c7d8fac6776245450b61827d2f37a996acbe5c768f302b6b298a78aab67568b9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.6.12
|
Release files / pypthon-0.3.2-py3-none-any.whl
| Download URL | pypthon-0.3.2-py3-none-any.whl |
|---|---|
| Size | 20.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
926307d40798dbf91d7bee6e111f3253f68ead3f7bac3c2b6ec26b2761eb86ce
|
|
BLAKE2b-256 checksum How to use checksums |
5daee5e940f1507f06a861c3f45c3c26b7940891bf5ea0dd1327c94227de5e15
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.3.0 pkginfo/1.6.1 requests/2.25.1 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.55.0 CPython/3.6.12
|