{"id":17034978,"url":"https://github.com/justquick/shell-pipes","last_synced_at":"2026-04-10T20:58:29.771Z","repository":{"id":57466723,"uuid":"336164189","full_name":"justquick/shell-pipes","owner":"justquick","description":"Extending Python syntax to implement shell commands as pipes using subprocess","archived":false,"fork":false,"pushed_at":"2021-02-05T04:34:48.000Z","size":12,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-01-28T02:12:32.001Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/justquick.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-02-05T04:33:36.000Z","updated_at":"2022-03-25T01:48:47.000Z","dependencies_parsed_at":"2022-09-10T02:00:30.403Z","dependency_job_id":null,"html_url":"https://github.com/justquick/shell-pipes","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justquick%2Fshell-pipes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justquick%2Fshell-pipes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justquick%2Fshell-pipes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/justquick%2Fshell-pipes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/justquick","download_url":"https://codeload.github.com/justquick/shell-pipes/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245026333,"owners_count":20549122,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-14T08:45:10.107Z","updated_at":"2026-04-10T20:58:24.747Z","avatar_url":"https://github.com/justquick.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Python Shell Pipes\n\n### A simple way to access your shell commands in Python\n\nThe `shpipes` package uses `subprocess.Popen` to run commands in a shell easily from native Python.\n\n```python\n    \u003e\u003e\u003e from shpipes import Pipe\n    # python --version\n    \u003e\u003e\u003e Pipe('python')('--version').getvalue()\n    'Python 3.8.6\\n'\n```\n\n## Chaining pipes together\n\nYou can chain together your commands, passing output from one to the input of another, similar to shell pipes. You can use the bitwise inclusive or operator to chain `Pipe` instances together.\n\n```python\n    # echo 1+1 | bc\n    \u003e\u003e\u003e (Pipe('echo')('1+1') | Pipe('bc')).getvalue()\n    '2\\n'\n    # This also works\n    \u003e\u003e\u003e pipe = Pipe('echo')('1+1')\n    \u003e\u003e\u003e pipe |= Pipe('bc'))\n    \u003e\u003e\u003e pipe.getvalue()\n    '2\\n'\n```\n\n### Loading commands from your `PATH`\n\nShell Pipes can also collect all executables from your `PATH` variable and gather them into a `Commands` instance so you can use the lib just like your native shell.\n\n```python\n    \u003e\u003e\u003e from shpipes import Commands\n    \u003e\u003e\u003e shell = Commands()\n    # find . -type f | grep .py$ | wc -l\n    \u003e\u003e\u003e (shell.find('.', '-type', 'f') | shell.grep('.py$') | shell.wc('-l')).getvalue()\n    '9\\n'\n    # this also works\n    \u003e\u003e\u003e pipe = shell.find('.', '-type', 'f')\n    \u003e\u003e\u003e pipe |= shell.grep('.py$')\n    \u003e\u003e\u003e pipe |= shell.wc('-l')\n    \u003e\u003e\u003e pipe.getvalue()\n    '9\\n'\n```\n\n\n### Handling pipe arguments\n\nWhen a `Pipe` is called, its arguments are directly passed to `Popen` so beware that strings must be quoted properly.\nYou can use `getvalue()` to get the output from one pipe and then pass it as a command argument instead of input text.\nPipes are only evaluated when `getvalue()` is called\n\n```python\n    \u003e\u003e\u003e license = shell.find('.', '-name', '\"LICENSE\"').getvalue()\n    \u003e\u003e\u003e shell.wc(license).getvalue()\n    '  21  169 1069 ./LICENSE\\n'\n```\n\n## Shell by default\n\nSince pipes run in a shell by default, environment variables evaluate automatically\n\n```python\n\n    \u003e\u003e\u003e pipe = shell.ps('-u $USER')\n    \u003e\u003e\u003e pipe |= shell.grep('python')\n    \u003e\u003e\u003e pipe |= shell.head('-1')\n```\n\n### Configuration options\n\nIf you need to run a different shell or disable shell entirely, then you can pass options via environment variables or kwargs to `Pipe`\n\n\n### Overriding options in `Pipe`\n\nYou can override all options to `Popen` (except `stdin`/`stdout`) by passing arguments to `Pipe`\nBy default `Popen` is run in shell mode with your default shell.\n\n```python\n    \u003e\u003e\u003e Pipe('ls', executable='/bin/zsh', cwd='/var', shell=False)\n```\n\n### Set env `SHPIPES_NO_SHELL`=true\n\nSets `shell=False` in the call to `Popen`\n\n### Set env `SHPIPES_SHELL`=/bin/zsh\n\nChanges the executable shell run by `Popen`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjustquick%2Fshell-pipes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjustquick%2Fshell-pipes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjustquick%2Fshell-pipes/lists"}