Skip to main content

Pypthon

Pipes for python3 to be used in shell

cfilter demo

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)

Source distribution for pypthon 0.3.2
File Size Uploaded Provenance Actions
pypthon-0.3.2.tar.gz 6.2 kB Without provenance Details for pypthon-0.3.2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pypthon 0.3.2
File Interpreter ABI Platform Actions
pypthon-0.3.2-py3-none-any.whl Python 3 none any Details for pypthon-0.3.2-py3-none-any.whl

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

Security for pypthon 0.3.2

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page