Skip to main content

Command that pipes data from bash to Python, and vice-versa

Project description

Pyped: command that pipes data from bash to Python, and vice-versa

Ever wish you could do this::

$ ps aux | py "'-'.join(x.split()[:3])" | grep 0.1

Or this::

$ ls -1 | py -i "Counter([path.splitext(line)[1] for line in x]).items()"
(u'.sh', 2)
('', 3)
(u'.sh~', 3)
(u'.py', 4)
(u'.desktop', 1)

Pyped make that possible by giving you the `py` commande.

How to install ?

Just type::

pip install pyped

Please note this is alpha code, it will void your waranty, you may take weight,
loose your job and your wife and endorse unspeakable believes.

How to use ?


shell_command | py [-options] "any python instructions" [| another_shell_function]

Your python code will have access to the variable `x`, which will be a line from
stdin converted to unicode. All lines from stdin will be stuffed
to `x`, and then your python code will be executed.

Your code MUST return something convertible to unicode, as unicode() will be called on it.


ls /etc/ | grep conf | tail | py "x.upper()"

There is only one option at the moment::


If you pass `-i`, then `x` will not contain a string, but an iterable for which
each call to `next()` return a line of stdin, converted to unicode.

In that case you code MUST return an iterable for which
each call to `next()` return an object convertible to unicode, as unicode
will be called on it.


ls /etc/ | grep conf | tail | py -i "[i.upper() for i in x]"

Note that before doing any processing, we import several modules so they are
immidiatly available in your Python code::

import sys
import os
import re
import json
import base64
import calendar
import bz2
import pickle
import csv
import urllib
import urllib2
import zlib
import xml
import datetime
import itertools
import random
import hashlib
import operator
import tempfile

from os import path
from uuid import uuid1, uuid3, uuid4, uuid5
from datetime import datetime, date, time
from random import randint, random, randrange, choice
from collections import Counter, OrderedDict
from math import *

import lxml
except ImportError:

import requests
except ImportError:

import envoy
except ImportError:

import tablib
except ImportError:

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for Pyped, version 0.1
Filename, size File type Python version Upload date Hashes
Filename, size Pyped-0.1.tar.gz (2.7 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page