{"id":44794378,"url":"https://github.com/jaykv/pybash","last_synced_at":"2026-02-16T12:25:49.718Z","repository":{"id":62394602,"uuid":"560200325","full_name":"jaykv/pybash","owner":"jaykv","description":"\u003eexecute bash commands easily from python","archived":false,"fork":false,"pushed_at":"2024-02-19T00:34:22.000Z","size":85,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-02-19T01:32:03.562Z","etag":null,"topics":["bash","python"],"latest_commit_sha":null,"homepage":"","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/jaykv.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,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2022-11-01T00:25:30.000Z","updated_at":"2024-02-19T01:32:06.113Z","dependencies_parsed_at":"2024-02-19T01:42:11.605Z","dependency_job_id":null,"html_url":"https://github.com/jaykv/pybash","commit_stats":null,"previous_names":["jaykv/pybash"],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/jaykv/pybash","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaykv%2Fpybash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaykv%2Fpybash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaykv%2Fpybash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaykv%2Fpybash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jaykv","download_url":"https://codeload.github.com/jaykv/pybash/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jaykv%2Fpybash/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":29507902,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-02-16T09:05:14.864Z","status":"ssl_error","status_checked_at":"2026-02-16T08:55:59.364Z","response_time":115,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["bash","python"],"created_at":"2026-02-16T12:25:45.758Z","updated_at":"2026-02-16T12:25:49.712Z","avatar_url":"https://github.com/jaykv.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PyBash\n\n![GitHub Workflow Status (with branch)](https://img.shields.io/github/actions/workflow/status/jaykv/pybash/python-app.yml?branch=main)\n![PyPI - Downloads](https://img.shields.io/pypi/dm/pybash)\n![PyPI](https://img.shields.io/pypi/v/pybash)\n![GitHub](https://img.shields.io/github/license/jaykv/pybash)\n\nStreamline bash-command execution from python with a new syntax. It combines the simplicity of writing bash scripts with the flexibility of python. Under the hood, any line or variable assignment starting with `$` or surrounded by parentheses is transformed to python `subprocess` calls and then injected into `sys.meta_path` as an import hook. All possible thanks to the wonderful [ideas](https://github.com/aroberge/ideas) project!\n\nFor security and performance reasons, PyBash will NOT execute as shell, unless explicitly specified with a `\u003e` instead of a single `$` before the command. While running commands as shell can be convenient, it can also spawn security risks if you're not too careful. If you're curious about the transformations, look at the [unit tests](test_pybash.py) for some quick examples.\n\nNote: this is a mainly experimental library.\n\n# Setup\n\n## As standalone transformer\n`pip install pybash`\n\n\n```python\nfrom pybash.transformer import transform\n\ntransform(\"$echo hello world\") # returns the python code for the bash command as string\n```\n\n## As script runner\n`pip install \"pybash[script]\"`\n\n\n### Example \n```py\ntext = \"HELLO WORLD\"\n$echo f{text}\n```\n\n### Run script:\n```bash\npython -m pybash hello.py\n```\n\n# Supported transforms\n\n### 1. Simple execution with output\n```python\n$python --version\n$echo \\\\nthis is an echo\n```\noutputs:\n```\nPython 3.9.15\n\nthis is an echo\n```\n\n### 2. Set output to variable and parse\n```python\nout = $cat test.txt\ntest_data = out.decode('utf-8').strip()\nprint(test_data.replace(\"HELLO\", \"HOWDY\"))\n```\noutputs:\n```\nHOWDY WORLD\n```\n\n### 3. Wrapped, in-line execution and parsing\n```python\nprint(($cat test.txt).decode('utf-8').strip())\n```\noutputs:\n```\nHELLO WORLD\n```\n\n### 4. Redirection\n```python\n$echo \"hello\" \u003e\u003e test4.txt\n```\n\n### 5. Pipe chaining\n```python\n$cat test.txt | sed 's/HELLO/HOWDY/g' | sed 's/HOW/WHY/g' | sed 's/WHY/WHEN/g'\n```\noutputs:\n```\nWHENDY WORLD\n```\n\n### 6. Redirection chaining\n```python\n$cat test.txt | sed 's/HELLO/HOWDY\\\\n/g' \u003e test1.txt \u003e\u003e test2.txt \u003e test3.txt\n```\n\n### 7. Chaining pipes and redirection- works in tandem!\n```python\n$cat test.txt | sed 's/HELLO/HOWDY\\\\n/g' \u003e test5.txt\n```\n\n### 8. Input redirection\n```python\n$sort \u003c test.txt \u003e\u003e sorted_test.txt\n```\n\n```python\n$sort \u003c test.txt | sed 's/SORT/TEST\\\\n/g'\n```\n### 9. Glob patterns with shell\n```python\n\u003els .github/*\n```\n\n### 10. Direct interpolation\nDenoted by {{code here}}. Interpolated as direct code replace. The value/output of the variable, function call, or the expression must not include spaces.\n\n```python\n## GOOD\ncommand = \"status\"\ndef get_option(command):\n    return \"-s\" if command == \"status\" else \"-v\"\n$git {{command}} {{get_option(command)}}\n\ndisplay_type = \"labels\"\n$kubectl get pods --show-{{display_type}}=true\n\n## BAD\noption = \"-s -v\"\n$git status {{option}}\n\noptions = ['-s', '-v']\n$git status {{\" \".join(options)}}\n\n# use dynamic interpolation\noptions = {'version': '-v'}\n$git status {{options['version']}}\n```\n\n### 11. f-string interpolation\nDenoted by f{ any python variable, function call, or expression here }. Interpolated as f-string. The output of the variable, function call, or the expression must still not include spaces.\n\n```python\n## GOOD\n\n# git -h\noptions = {'version': '-v', 'help': '-h'}\n$git f{options['h']}\n\n# kubectl get pods --show-labels -n coffee\nnamespace = \"coffee\"\n$kubectl get pods f{\"--\" + \"-\".join(['show', 'labels'])} -n f{namespace}\n\n## BAD\noption = \"-s -v\"\n$git status f{option}\n```\n\n#### Also works inside methods!\n```python\n# PYBASH DEMO #\ndef cp_test():\n    $cp test.txt test_copy.txt\n\ncp_test()\n```\n\n# Dev\n\n#### Demo\n`python -m pybash examples/hello.py`\n`python -m pybash demo`\n\n#### Debug\n`make debug` to view the transformed source code\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaykv%2Fpybash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjaykv%2Fpybash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaykv%2Fpybash/lists"}