pypyp - Run Python at the Shell
pypyp (Python at Your Prompt) is a command-line utility that allows users to easily execute Python code directly from their shell, often leveraging shell piping for data manipulation. It's designed to be a magical yet never mysterious tool for quick data processing and scripting, similar to `awk` or `sed` but with Python's full power. The current version is 1.3.0, and releases are generally made as features or fixes are needed.
Warnings
- gotcha Understanding the input variables (`x`, `_`, `_i`) is crucial. `x` always refers to the raw input (a line when iterating, or the full input if not iterating). `_` refers to the currently iterated item (e.g., after `x.split()`). `_i` is the iteration index.
- gotcha Shell quoting can be tricky for Python expressions. Depending on the shell and the complexity of your Python code (e.g., involving dollar signs, backticks, or other shell special characters), you might need to experiment with single vs. double quotes, or escaping.
- gotcha pypyp is designed for concise, single-expression or short-script execution. While it uses the full Python interpreter, it's not optimized for running large, multi-file Python applications. Performance and best practices for complex scripts should use standard `python` execution.
Install
-
pip install pypyp
Imports
- cli_entrypoint
from pypyp.cli import cli_entrypoint
Quickstart
echo "hello world" | pypyp 'x.upper()'