{"id":13937839,"url":"https://github.com/sakshamsharma/zpyi","last_synced_at":"2025-09-24T03:32:27.668Z","repository":{"id":90141214,"uuid":"52175803","full_name":"sakshamsharma/zpyi","owner":"sakshamsharma","description":"The power of python in your Zsh - Unobtrusive and easy python scripting in shell","archived":false,"fork":false,"pushed_at":"2017-08-13T07:46:31.000Z","size":33,"stargazers_count":107,"open_issues_count":6,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-11-27T06:36:45.117Z","etag":null,"topics":["python","shell","tool","zsh"],"latest_commit_sha":null,"homepage":"http://sakshamsharma.github.io/zpyi/","language":"Shell","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/sakshamsharma.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":"2016-02-20T21:11:53.000Z","updated_at":"2024-10-24T19:44:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"9ab1f608-d9d3-4a4a-bca8-7510a7221a01","html_url":"https://github.com/sakshamsharma/zpyi","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/sakshamsharma%2Fzpyi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sakshamsharma%2Fzpyi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sakshamsharma%2Fzpyi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sakshamsharma%2Fzpyi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sakshamsharma","download_url":"https://codeload.github.com/sakshamsharma/zpyi/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234033412,"owners_count":18769180,"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":["python","shell","tool","zsh"],"created_at":"2024-08-07T23:03:57.224Z","updated_at":"2025-09-24T03:32:22.332Z","avatar_url":"https://github.com/sakshamsharma.png","language":"Shell","funding_links":[],"categories":["Shell","Command-Line Productivity"],"sub_categories":["Directory Navigation"],"readme":"zpyi\n====\n\nzpyi makes your shell smarter, in more ways than one. It's no magic, it's python.\n\n```\n                    _\n                   (_)\n ____ _ __   _   _  _\n|_  /| '_ \\ | | | || |\n / / | |_) || |_| || |\n/___|| .__/  \\__, ||_|\n     | |      __/ |\n     |_|     |___/\n```\n\nYour shell now falls back to python if some command couldn't be handled by zsh.\nSo you can now do `2+3` directly in your shell. Well, something much more complex than that too.\n\nOf course, to prevent breaking any existing functionality provided by Zsh,\nyou need to use `'2**107'` instead of `2**107` and the likes. Simply enclose your python program by some unused delimiters, and you're good to go.\n\nYou can assume that anything written at the start of a shell command, within single or double quotes would be interpreted as a python script.\n\nAlso, now instead of piping shell output to age-old (and still awesome, don't get me wrong) programs like `awk`, `grep`, `sed`, you can **actually** pipe shell output to short Python inline scripts, just like the good old `awk` scripts.\n\nOf note, this is **not** a subset of `python -c`. `python -c` will *not* let you run python programs. It lets you run interactive python commands. Using `zpyi`, you can actually write programs and keep them in shell history, just like you've been doing with `awk` and `grep` since ages.\n\n# Examples\nHere are some cool things you can now do. Note that all the code blocks below are to be run in the shell itself! No need to write python scripts to do small one-time stuff. And all this stays in your shell history! No need to store your small scripts too.\n\n#### Cool One liners\n* `'2**107'`\n* `'sqrt(10)'`\n* `'\"user\".upper()'`\n* Multiline code!\n```\n'\na = 1\nb = 2**107\nc = a + b\nprint (c*2)\n'\n```\n\n#### Use shell commands and env vars inside python code\n* `\"print ('$(whoami)'.upper())\"`\n* `export myname=\"me\"; \"print ('$myname is nice')\"`\n\n#### Pass stuff to python script using stdin\n```\ncat /etc/passwd | '\nlines = sys.stdin.readlines()\n\nfor line in lines:\n    print line.upper()\n'\n```\n\n#### Stdin and Stdout redirection\n* `'print (input().upper())' \u003c infile \u003e outfile`\n* `echo \"what, my name is shady\" | 'print (input().upper())'`\n\n#### Command line parameters\nYes, they work too, using either the `sys.argv` or `argv` to refer to the 1 based indexing.\nThere is also an array named `args` which has the args in 0 based indexing\n\n* `'print (str(int(sys.argv[1]) + int(sys.argv[2])))' 2 3` returns 5\n* `'print (str(int(args[0]) + int(args[1])))' 2 3` returns 5 too\n\n#### Imports!\nThe modules `math`, `sys` and `os` are already imported!\n\nIn addition, you can define an environment variable to use any custom imports, thanks to @orf for the PR on this!\n```\n# This is a shell command, run in your shell\nexport ZPYI_IMPORTS=requests\n\n# This is the python line you run\n\"get('http://google.com')\"\n```\n\nSo now you don't need to run `python -c 'print(sqrt(2**10))' \u003e outputfile`, only to remember that it won't work because `math` is not imported while using `python -c`.\n\n#### Write cool shell scripts\nHere's a simple zsh script to be run via `zsh script.sh`. Just that now you don't need to do complicated string parsing in shell, when you have python for that.\n```\nsource ~/.zshrc\nmyname=$(whoami)\n\"print ('${myname}'.upper())\"\n```\n\n# Installing?\nThe installation script is concise enough:\n```\ncd ~\ngit clone https://github.com/sakshamsharma/zpyi ~/.zpyi\necho \"source ~/.zpyi/zpyi.zsh\" \u003e\u003e ~/.zshrc\nsource ~/.zshrc\n```\n\nIf you feel lazy, this works too:\n```\ncurl https://raw.githubusercontent.com/sakshamsharma/zpyi/master/install_script.sh | bash\n```\n\nOr if you make use of [antigen](https://github.com/zsh-users/antigen) (which is probably a good idea):\n```\nantigen bundle https://github.com/sakshamsharma/zpyi zpyi.zsh\n```\n\n# Uninstallation\n```\nrm -rf ~/.zpyi\nsed -i '/zpyi.zsh/d' ~/.zshrc\n```\n\n# TODO\n* Add support for querying for missing packages\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsakshamsharma%2Fzpyi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsakshamsharma%2Fzpyi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsakshamsharma%2Fzpyi/lists"}