Skip to main content

No project description provided

Project description

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.

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

pypthon-0.3.2.tar.gz (6.2 kB view details)

Uploaded Source

Built Distribution

pypthon-0.3.2-py3-none-any.whl (20.3 kB view details)

Uploaded Python 3

File details

Details for the file pypthon-0.3.2.tar.gz.

File metadata

  • Download URL: pypthon-0.3.2.tar.gz
  • Upload date:
  • Size: 6.2 kB
  • Tags: Source
  • Uploaded using 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

File hashes

Hashes for pypthon-0.3.2.tar.gz
Algorithm Hash digest
SHA256 df3245c2e9676288c338069c8144d2b45add42b8c294708edf9b4e86eca0077e
MD5 3fdf44cf5eca0470a9d8014078897b8d
BLAKE2b-256 c7d8fac6776245450b61827d2f37a996acbe5c768f302b6b298a78aab67568b9

See more details on using hashes here.

File details

Details for the file pypthon-0.3.2-py3-none-any.whl.

File metadata

  • Download URL: pypthon-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 20.3 kB
  • Tags: Python 3
  • Uploaded using 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

File hashes

Hashes for pypthon-0.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 926307d40798dbf91d7bee6e111f3253f68ead3f7bac3c2b6ec26b2761eb86ce
MD5 1597862abb2602f30ff996b3b2afadb3
BLAKE2b-256 5daee5e940f1507f06a861c3f45c3c26b7940891bf5ea0dd1327c94227de5e15

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