skip to navigation
skip to content

Not Logged In

toolshed 0.2.9

Tools for data

Latest Version: 0.4.4

Toolshed: Less Boiler-Plate

This is a collection of well-tested, simple modules and functions
that I use frequently


If you have a "proper" CSV file with quoting and such, use python's `csv`_

If all you have is a file with a header and you want to get a dictionary
for each row::

>>> from toolshed import reader, header, nopen
>>> for d in reader('src/toolshed/tests/data/file_data.txt'):
... print d['a'], d['b'], d['c']
1 2 3
11 12 13
21 22 23

works the same for gzipped, bzipped, and .xls files and for stdin (via "-")
and for files over http/ftp::

>>> for drow in (d for d in reader('src/toolshed/tests/data/file_data.txt.gz') if int(d['a']) > 10):
... print drow['a'], drow['b'], drow['c']
11 12 13
21 22 23

if one can specify the header to a file without one using the `header=` kwarg.
If `header` is "ordered" then an OrderedDictionary will be used so that
drow.keys() and d.values() will return the values in the order they appeared in the file.

If `header` is a callable (a function or class) then, for each row, that
callable will be called for each row with a single argument which is the
list of columns in the future, it may be called as: callable(\*row) instead
of callable(row). **comments welcome**.

sometimes you just want the header::

>>> header('src/toolshed/tests/data/file_data.txt')
['a', 'b', 'c']

the `toolshed.nopen` can open a file over http, https, ftp, a gzipped file, a
bzip file, or a subprocess with the same syntax.

>>> nopen('src/toolshed/tests/data/file_data.txt.gz')
<gzip open="" file="" ...="">
>>> nopen('|ls')
<open file="" '<fdopen="">'...>


Shedskin is a program that takes python scripts, infers the types based
on example input and generates fast C++ code that compiles to a python
extension module. Shedskinner is a decorator that automates this for a single
function. Use looks like::

from toolshed import shedskinner

@shedskinner((2, 12), long=True, fast_random=True):
def adder(a, b):
return a + b

Where here, we have decorated the adder function to make it a compiled, fast
version that accepts and returns integers. The (2, 12) are example arguments
to the function so that shedskin can infer types.
The keyword arguments are sent to the compiler (see: for more examples.


.. _`csv`:

support for bash process substition, e.g.: reader("|cmd <(some args)")

reader supports streaming remote .gz files.

* reader supports .xls files.

* don't print an extra newline when reading empty stderr from a process.

* allow splitting on none or on regexp.

* if header is a callable, it's called for each row (instead of returning

* if reader can accept the generator returned from reader()

* if an integer is sent to nopen, then nopen(sys.argv[arg]) is returned.

* fix handling when there's an exception in the loop that calls a process

* better error message from Popen when using nopen("| something")

* if the header argument to `reader` is "ordered" then an ordered
dictionary is used.

* Add is_newer_b(apath, bpaths) to check that all b files are newer
than apath.

* July 26 2011
* Allow ftp/http(s) paths as arguments to reader

* use itertools.izip for speed improvement


*Release date: 15-Mar-2010*

* Initial project structure.  
File Type Py Version Uploaded on Size
toolshed-0.2.9.tar.gz (md5) Source 2012-12-18 7KB
  • Downloads (All Versions):
  • 2 downloads in the last day
  • 276 downloads in the last week
  • 1794 downloads in the last month