Another tool for your python toolset. General odds and ends that kept coming up in projects.


$ pip install screwdriver


screwdriver has been tested with Python 2.7, 3.6 and 3.7


class screwdriver.DictObject(src)

Acts as a wrapper to a dictionary so that keys can be accessed as properties.

>>> d = DictObject({'x'=1, 'y'=2})
>>> d.x
>>> d._src
{'x':1, 'y':2}

Equivalent of “from X import Y” statement using dot notation to specify what to import and return. For example, returns the item “thing” in the module “”


Returns a tuple consisting of the head of a enumerable, the middle as a list and the tail of the enumerable. If the enumerable is 1 item, the middle will be empty and the tail will be None.

>>> head_tail_middle([1, 2, 3, 4])
1, [2, 3], 4
screwdriver.list_to_rows(src, size)

A generator that takes a enumerable item and returns a series of slices. Useful for turning a list into a series of rows.

>>> list(list_to_rows([1, 2, 3, 4, 5, 6, 7], 3))
[[1, 2, 3], [4, 5, 6], [7, ]]

Parses an HTML anchor tag, returning the href and content text. Any content before or after the anchor tag pair is ignored.

Parameters:html – Snippet of html to parse
Returns:namedtuple(‘ParsedLink’, [‘url’, ‘text’])


>>> parse_link('things <a href="/foo/bar.html">Foo</a> stuff')
ParsedLink('/foo/bar.html', 'Foo')

Alternative to pprint.PrettyPrinter() that uses json.dumps() for sorting and displaying data.

Parameters:data – item to print to STDOUT. The item must be json serializable!

Takes a two dimensional array and returns an new one where rows in the first become columns in the second.

Indices and tables