Compatibility shim for Python's removed pipes module (Python 3.13+)
The pipes module was deprecated in Python 3.11 and removed in Python 3.13 (PEP 594). This package provides a compatibility layer for code that still depends on the pipes module.
pip install pipes-compatThe most common use case is the quote() function for shell escaping:
import pipes
# Shell-escape a string
escaped = pipes.quote("hello world")
print(escaped) # 'hello world'The Template class allows you to build and execute shell pipelines:
import pipes
# Create a pipeline template
t = pipes.Template()
# Add commands to the pipeline
t.append('grep "error"', 'f')
t.append('sort', 'f')
t.append('uniq', 'f')
# Execute the pipeline
t.copy('input.txt', 'output.txt')
# Or use with stdin/stdout
t.copy('-', '-') # stdin to stdout
t.copy('input.txt', '-') # file to stdoutimport pipes
t = pipes.Template()
t.append('tr "[:lower:]" "[:upper:]"', 'f')
t.append('head -n 10', 'f')
# Open a file through the pipeline
with t.open('input.txt', 'r') as f:
content = f.read()
# Enable debugging
t.debug(True)
t.copy('input.txt', 'output.txt') # Prints command to stderrReturn a shell-escaped version of the string s. This is a compatibility shim for pipes.quote(), using shlex.quote() internally.
A class for creating and executing shell pipelines.
append(cmd: str, kind: str) -> None: Append a command to the end of the pipelineprepend(cmd: str, kind: str) -> None: Prepend a command to the beginning of the pipelinereset() -> None: Reset the template to its initial stateclone() -> Template: Return a copy of the templatedebug(flag: bool) -> None: Enable or disable debugging outputopen(file: str, mode: str) -> IO: Open a file through the pipelinecopy(infile: str, outfile: str) -> None: Copy a file through the pipeline
- This shim uses
subprocessinternally, which is the recommended replacement forpipes - The implementation prioritizes compatibility over performance
- For new code, consider using
subprocessdirectly instead of this compatibility shim - Some edge cases in the original
pipesmodule may behave slightly differently
- Python 3.13 or later
To set up the development environment:
# Install the package in development mode with dev dependencies
pip install -e ".[dev]"To run the test suite:
pytestTo run tests with coverage:
pytest --cov=pipes --cov-report=htmlTo run linting with Ruff:
ruff check .
ruff format --check .To auto-fix linting issues:
ruff check --fix .
ruff format .Apache-2.0
Contributions are welcome! Please feel free to submit issues or pull requests.