{ "info": { "author": "Kevin Samuel", "author_email": "kevin.samuel@yandex.com", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "Operating System :: OS Independent", "Programming Language :: Python" ], "description": "Pyped: command that pipes data from bash to Python, and vice-versa\n=================================================================\n\n*WARNING: since the last version the command line name \"py\" has been\nrenamed to \"pyp\" to avoid conflict with the new tool in the Python\nstdlib named \"py\". It means pyped is now incompatible with the\n\"Python Power at the Prompt\" project sharing the same name and goals.*\n\nPyped is a command-line tool that let you process another command\noutput with a Python one-liner like Perl or AWK.\n\nEver wish you could do this::\n\n $ ps aux | pyp \"line = x.split()\" \"print(line[1], line[-1])\" | grep worker\n 18921 [kworker/1:2]\n 22489 [kworker/3:0]\n 24065 [kworker/3:3]\n 24869 [kworker/u:3]\n 25463 [kworker/u:1]\n 25511 [kworker/2:2]\n 25720 [kworker/0:2]\n 26343 [kworker/0:1]\n 26491 [kworker/2:0]\n 26569 [kworker/1:0]\n 26592 [kworker/u:0]\n 26861 worker\n\nOr this::\n\n $ ls -1 | pyp -i \"for x in Counter(path(x.split()[-1]).ext for x in l).items(): print(x)\"\n (u'.sh', 2)\n ('', 3)\n (u'.sh~', 3)\n (u'.py', 4)\n (u'.desktop', 1)\n\n\nPyped make that possible by giving you the `py` commande.\n\nHow to install ?\n=================\n\nJust type::\n\n pip install pyped\n\nIt works with Python 2.7 and 3.4, although it uses __future__ imports to\nenforce a lot of 3.X stuff such as unicode literals and the print() function.\n\nHow to use ?\n=============\n\nUsage::\n\n $ pyp \"any python one-liner\"\n $ shell_command | pyp [options] \"any python one-liner\" [another python one-liner] [| another_shell_function]\n\nIn the second example, you pipe data to pyped. In that case, you python code\nwill have access to the variable `x`, which will be a line from\nstdin converted to unicode (with no ending '\\n'). Each line from stdin\nwill be stuffed to `x` one by one, and your python code\nwill be executed for each new value for `x`\n\nYou'll also have access to the variable `i`, an integer incremented at each\ncall of you Python statement, starting from 0.\n\nYour code MUST print something, if you wish something to appear.\n\nWithout Pyped::\n\n $ echo \"test\"\n test\n $ ls /etc | tail\n wordpress\n wpa_supplicant\n X11\n xdg\n xml\n xul-ext\n xulrunner-1.9.2\n y-ppa-manager.conf\n zsh\n zsh_command_not_found\n\nWith Pyped::\n\n $ pyp \"print('test')\"\n test\n $ ls /etc/ | tail -n 4 | pyp \"print('%s %s' % (i, x.upper()))\"\n 0 WPA_SUPPLICANT\n 1 X11\n 2 XDG\n 3 XML\n\nYou can even make long one time scripts::\n\n $ ps aux | pyp \"\n if i > 0:\n values = x.split()\n user, pid = values[:2]\n command = ' '.join(values[10:])\n if user != 'root':\n print('\\\"%s\\\";\\\"%s\\\";\\\"%s\\\"' % (user.upper(), pid, command))\n \"\n \"SYSLOG\";\"741\";\"rsyslogd -c5\"\n \"AVAHI\";\"788\";\"avahi-daemon: running\"\n \"AVAHI\";\"791\";\"avahi-daemon: chroot helper\"\n \"DAEMON\";\"1271\";\"atd\"\n \"WHOOPSIE\";\"1289\";\"whoopsie\"\n \"MYSQL\";\"1304\";\"/usr/sbin/mysqld\"\n \"ME\";\"1699\";\"ps aux\"\n \"ME\";\"2167\";\"-\"\n \"TIMIDITY\";\"2202\";\"/usr/bin/timidity -Os -iAD\"\n \"RTKIT\";\"2594\";\"/usr/lib/rtkit/rtkit-daemon\"\n \"ME\";\"2763\";\"/usr/bin/gnome-keyring-daemon --daemonize --login\"\n \"ME\";\"2774\";\"gnome-session --session=ubuntu\"\n\n\nOptions\n=======\n\n-i\n***\n\nIf you pass `-i`, then `x` will not exists, but `l` will contain\nan iterable for which each call to `next()` return a line of stdin,\nconverted to unicode.\n\nIt is mainly used for processing you wish to apply to the whole stdin such as joining or for global counters.\n\nE.G::\n\n $ ls /etc/ | tail -n 4 | pyp -i \"print('-'.join(i.strip() for i in l))\"\n wpa_supplicant-X11-xdg-xml\n\n-p\n***\n\nAutomatically print the result of your Python expression.\n\nE.G::\n\n $ ls /etc/ | tail -n 4 | pyp -p 'x.upper()'\n WPA_SUPPLICANT\n X11\n XDG\n XML\n\nIf your expression returns None, the line is not printed.\n\nWARNING : other flags usually accept Python **statement** (if, for, etc). If\nyou use this flag, most of them will now only accect **expressions**\n(stuff you can pass directly to the print function).\n\n-s\n***\n\nSplit input using a Python regex. Result will be stored in \"f\". 'x', 'i' and\n'stdin' are still available.\n\nE.G::\n\n $ echo \"a b c\" | pyp -s \"\\s+\" \"print(f)\"\n [u'a', u'b', u'c']\n $ echo \"a-b-c\" | pyp -s \"-\" \"print(f)\" \"print(x)\"\n [u'a', u'b', u'c']\n a-b-c\n\n\n-f\n***\n\nFilter input using a Python expression (like grep, but on any python condition).\n\nE.G::\n\n $ cat /etc/fstab | pyp -f 'len(x) < 45 and \"/\" in x'\n # / was on /dev/sda7 during installation\n # swap was on /dev/sda6 during installation\n\nIf an exception is raised in quiet mode, the line is skiped.\n\nWARNING : other flags accept Python **statement** (if, for, etc). This flags\nonly accept **expressions** (stuff you can pass directly a if keyword).\n\n-b\n***\n\nPass a statement you wish to run BEFORE reading from stdin.\nMainly used for imports.\n\nE.G::\n\n $ ls /etc/ | tail -n 4 | pyp \"print(pickle.dumps(x))\" -b \"import pickle\"\n Vwordpress\n p0\n .\n Vwpa_supplicant\n p0\n .\n VX11\n\nThis is executed only once.\n\n-a\n***\n\nPass a statement you wish to run AFTER reading all stdin.\n\nIs is executed in a finally clause, so it runs even if your code fails before.\n\nMainly used for counters and cleanup.\n\nE.G::\n\n $ ls /etc/ | tail -n 4 | pyp \"x\" -a 'print(i)'\n wpa_supplicant\n X11\n xdg\n xml\n 3\n\nThis is executed only once.\n\n-q\n***\n\nQuietly ignore exceptions.\n\n\n--full\n*****************\n\nPass the entire content of the standard input in a \"stdin\" variable.\n\nE.G::\n\n $ cat /etc/fstab | pyp \"print(len(x))\"\n 45\n 1\n 62\n 74\n 63\n 1\n 70\n 40\n 93\n 43\n 91\n 118\n\n $ cat /etc/fstab | pyp --full \"print(len(stdin))\"\n 713\n\n\n--stdin-charset\n*****************\n\nForce the charset to decode input. Otherwise, we try to\ndetect it, and fallback on UTF-8 if it fails.\n\nE.G::\n\n $ ls /etc/ | tail -n 4 | pyp \"x.split('-')[0]\" --stdin-charset ascii\n wpa_supplicant\n X11\n xdg\n xml\n\nBe careful, that could fail miserably if you choose a bad charset:\n\n $ ls /etc/ | tail -n 4 | pyp \"\u00e9\" --stdin-charset ascii\n 'ascii' codec can't decode byte 0xc3 in position 0: ordinal not in range(128)\n\n--rstrip\n************\n\nEach line from stdin has .rstrip('\\n') applied to it before being\npassed to your code so you can call `print()` without thinking about it.\n\nHowever, if you do wish to keep the line breaks, use --rstrip=''.\n\nThe usual result::\n\n $ ls /etc/ | pyp -i \"for x in list(l)[:5]: print(x)\"\n total 2,5M\n drwxr-xr-x 204 root root 12K d\u00e9c. 1 16:40 .\n drwxr-xr-x 26 root root 4,0K nov. 12 07:37 ..\n drwxr-xr-x 3 root root 4,0K mars 7 2013 acpi\n -rw-r--r-- 1 root root 3,0K avril 26 2011 adduser.conf\n\nThe result if you supress right stripping::\n\n $ ls /etc/ | pyp -i \"for x in list(l)[:5]: print(x)\" --rstrip=''\n total 2,5M\n\n drwxr-xr-x 204 root root 12K d\u00e9c. 1 16:40 .\n\n drwxr-xr-x 26 root root 4,0K nov. 12 07:37 ..\n\n drwxr-xr-x 3 root root 4,0K mars 7 2013 acpi\n\n -rw-r--r-- 1 root root 3,0K avril 26 2011 adduser.conf\n\n\n--json\n************\n\nParse stdin as JSON, and make the whole thing accessible in a \"j\" variable.\n\n $ echo '[{\"foo\": \"bar\"}]' | pyp -j \"print(j[0]['foo'])\"\n bar\n\n\nImports\n==========\n\nBefore doing any processing, we import several modules so they are\nimmediatly available in your Python code::\n\n import sys\n import os\n import re\n import json\n import base64\n import calendar\n import csv\n import itertools\n import random\n import hashlib\n import tempfile\n import argparse\n import random\n import math\n\n from itertools import *\n from uuid import uuid4\n from datetime import datetime, timedelta\n from collections import Counter, OrderedDict\n\nWe also import these 4 third party libraries::\n\n import arrow # better datetime\n import requests # better http request\n\n from minibelt import * # better itertools\n from path import path # better path handling\n\nThey should have been installed by setuptools automatically, so if you use pip or\neasy_install, you are good to go.\n\nIf you didn't, and you don't have them installed, these imports will be ignored.\n\nWhile Pyped is based on Python 2.7, it also imports some backported features\nfrom Python 3::\n\n from __future__ import (unicode_literals, absolute_import,\n print_function, division)\n\nThis means `print` is a function, any string is unicode by default and does\nnot need to be prefixed by `u`, division doesn't truncate and\nimports are absolute (but you can use the relative import syntax).\n\nThis way, pyped run on Python 3.", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/ksamuel/Pyped", "keywords": "python,pipe", "license": "GPL2", "maintainer": null, "maintainer_email": null, "name": "Pyped", "package_url": "https://pypi.org/project/Pyped/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/Pyped/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/ksamuel/Pyped" }, "release_url": "https://pypi.org/project/Pyped/1.4/", "requires_dist": null, "requires_python": null, "summary": "Replace sed/grep/cut/awk by letting you execute Python one-liners in your ordinary shell, like perl does.", "version": "1.4" }, "last_serial": 1124770, "releases": { "0.1": [ { "comment_text": "", "digests": { "md5": "0e3d2a4f08f626b0851f3f810680c42b", "sha256": "5e10cffcd468ddba71a6976d3716cf45c16dc43ed22eaaa44e090296cf3bac08" }, "downloads": -1, "filename": "Pyped-0.1.tar.gz", "has_sig": false, "md5_digest": "0e3d2a4f08f626b0851f3f810680c42b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 2658, "upload_time": "2012-02-18T03:41:32", "url": "https://files.pythonhosted.org/packages/10/fe/6e96a64c5f187aff7585286bb5331c5fdcf3dfc6e4dff0addc3349a1742f/Pyped-0.1.tar.gz" } ], "0.2": [ { "comment_text": "", "digests": { "md5": "1ec36e65a0a6f7cb81db4fbe9bed8bac", "sha256": "13ccd7e9a740647986661f9e6a2eb16c061be9ccf8cc0d9e0be6be0df8077269" }, "downloads": -1, "filename": "Pyped-0.2.tar.gz", "has_sig": false, "md5_digest": "1ec36e65a0a6f7cb81db4fbe9bed8bac", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11125, "upload_time": "2012-09-01T16:33:50", "url": "https://files.pythonhosted.org/packages/7e/dd/70edbd2767b4693a0f85e6d02388a4fd1ef81480e0fd25fdaa66617e2c10/Pyped-0.2.tar.gz" } ], "0.3": [ { "comment_text": "", "digests": { "md5": "04c4c52d88a9c0a193ff8f5198330485", "sha256": "cf649729fa329b125335d60527982cfefcc1ddcbf5ccf2977f4384ac444e30ab" }, "downloads": -1, "filename": "Pyped-0.3.tar.gz", "has_sig": false, "md5_digest": "04c4c52d88a9c0a193ff8f5198330485", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 11851, "upload_time": "2012-09-16T14:13:06", "url": "https://files.pythonhosted.org/packages/de/0d/a13feea3b847d97623dfe076774f6b64790e04b1ef8720003d4eb9e5dfc2/Pyped-0.3.tar.gz" } ], "1.0": [ { "comment_text": "", "digests": { "md5": "cf1ab2ab9811a89f40345d288a160dc7", "sha256": "4ff40ee245d1aa1d518e3c5557d556be50fa72872646a6d82a84667f6c49d70b" }, "downloads": -1, "filename": "Pyped-1.0.tar.gz", "has_sig": false, "md5_digest": "cf1ab2ab9811a89f40345d288a160dc7", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12284, "upload_time": "2013-12-02T15:18:16", "url": "https://files.pythonhosted.org/packages/04/86/7cdf04c7644caa9bf45e349d35072db1d11cb158529c929de1eb1796b291/Pyped-1.0.tar.gz" } ], "1.1": [ { "comment_text": "", "digests": { "md5": "022086c625e790a21eb264d277b882df", "sha256": "0ff2f01f6198dc0394ae993e555c837b5cf3f9300f40bf68c46fd9382ef3a7d9" }, "downloads": -1, "filename": "Pyped-1.1.tar.gz", "has_sig": false, "md5_digest": "022086c625e790a21eb264d277b882df", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 12711, "upload_time": "2014-03-06T11:39:47", "url": "https://files.pythonhosted.org/packages/c0/ca/fce57e9cb36fe570ac0e339aed72d40d16b782f809708bf7c5d14efd1dc2/Pyped-1.1.tar.gz" } ], "1.1.2": [ { "comment_text": "", "digests": { "md5": "03d9e8257b285f39e2d5661cd34ceef0", "sha256": "3e16bb4546d58bbe2c43d718ba119aa9a8f7d537967abc06de448a63a6aee912" }, "downloads": -1, "filename": "Pyped-1.1.2.tar.gz", "has_sig": false, "md5_digest": "03d9e8257b285f39e2d5661cd34ceef0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15543, "upload_time": "2014-03-19T07:30:59", "url": "https://files.pythonhosted.org/packages/3e/a1/a28f3cb1ea7599c7790cc8386c43b1854a7c2da4b4f6c43a8482cfc3e08c/Pyped-1.1.2.tar.gz" } ], "1.2": [ { "comment_text": "", "digests": { "md5": "2b5cc14bf99440fd1b85d30ca5f49e2d", "sha256": "be26ff2a801212b21b55d4562677224ff869afb6b0ff20f8e0b9c1f24e8afc5d" }, "downloads": -1, "filename": "Pyped-1.2.tar.gz", "has_sig": false, "md5_digest": "2b5cc14bf99440fd1b85d30ca5f49e2d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 16927, "upload_time": "2014-06-12T05:33:54", "url": "https://files.pythonhosted.org/packages/53/cb/26d9d918ae7c9674aabf23d1af2969abb7a2f8432aba0cd51945293ad435/Pyped-1.2.tar.gz" } ], "1.3": [ { "comment_text": "", "digests": { "md5": "3cd8154fd0701a1121a91fd8bb7545db", "sha256": "2fb1ce850b3a85690eeae8fb990384832e2512997bdc708bcac736e511daedcd" }, "downloads": -1, "filename": "Pyped-1.3.tar.gz", "has_sig": false, "md5_digest": "3cd8154fd0701a1121a91fd8bb7545db", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 17847, "upload_time": "2014-06-12T07:23:27", "url": "https://files.pythonhosted.org/packages/57/d9/9434d2486ed5025adf70aff2d16abf7eae51c1725570e60ca6872f422276/Pyped-1.3.tar.gz" } ], "1.4": [ { "comment_text": "", "digests": { "md5": "0e8f11948721252cd99b3e53e5a75774", "sha256": "ed458cfec5ef48a2cc2266f82f8c2b35efe5f63cd523612acddac953dd26a8d3" }, "downloads": -1, "filename": "Pyped-1.4.tar.gz", "has_sig": false, "md5_digest": "0e8f11948721252cd99b3e53e5a75774", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15460, "upload_time": "2014-06-14T12:09:42", "url": "https://files.pythonhosted.org/packages/40/0a/cae01e032fd6d6ccbc23cffc6210ffea99f453d97932d29ddefb1811df9b/Pyped-1.4.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "0e8f11948721252cd99b3e53e5a75774", "sha256": "ed458cfec5ef48a2cc2266f82f8c2b35efe5f63cd523612acddac953dd26a8d3" }, "downloads": -1, "filename": "Pyped-1.4.tar.gz", "has_sig": false, "md5_digest": "0e8f11948721252cd99b3e53e5a75774", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 15460, "upload_time": "2014-06-14T12:09:42", "url": "https://files.pythonhosted.org/packages/40/0a/cae01e032fd6d6ccbc23cffc6210ffea99f453d97932d29ddefb1811df9b/Pyped-1.4.tar.gz" } ] }