The Voidspace Python Modules
Welcome to the home of the voidspace python modules. These are modules and libraries that I've developed for use with Python. They are all fully open source, with an OSI Approved License. I hope you find them useful, and I welcome feedback. Check out the Python Index Page for links to my Python CGIs, programs, and smaller "recipes".
|The Voidspace Python Modules|
A Simple Class for Mocking in Unit Tests
Version 1.0.0 7th October 2012
mock provides a core Mock class that is intended to reduce the need to create a host of trivial stubs throughout your test suite. After performing an action, you can make assertions about which methods / attributes were used and arguments they were called with. You can also specify return values and set needed attributes in the normal way.
- Mock Library Homepage
- mock-6.0.zip (module, tests and documentation)
- mock.pdf (documentation)
- Google Code Home & Subversion Repository
It also provides utility functions / objects to assist with testing, particularly monkey patching.
In Python 2.7 and 3.2 a whole bunch of improvements to unittest arrived. unittest2 is a backport of the new features (and tests) to work with Python 2.4, 2.5, 2.6 & 3.1. The major changes include new assert methods, clean up functions, assertRaises as a context manager, new command line features, test discovery and the load_tests protocol.
Reading and Writing Config Files
Version 4.7.2 27th February 2010
Note that ConfigObj is not currently under development.
ConfigObj is a simple but powerful config file reader and writer: an ini file round tripper. It's main feature is that it is very easy to use, with a straightforward programmer's interface and a simple syntax for config files. It has lots of other features though. This module is used in most Voidspace projects. See the ConfigObj Home Page for full documentation.
It's features include :
Nested sections (subsections), to any level
Multiple Line Values
Full Unicode support
String interpolation (substitution)
Integrated with a powerful validation system
- including automatic type checking/conversion
- repeated sections
- and allowing default values
All comments in the file are preserved
The order of keys/sections is preserved
A powerful unrepr mode for storing basic datatypes
Download links :
The best introduction to working with ConfigObj, including the powerful configuration validation system, is the article: An Introduction to ConfigObj.
Create APIs that work as decorators and as context managers
A backport of a new feature from the contextlib module in Python 3.2. contextdecorator provides a ContextDecorator class that allows you to create APIs that work as both context managers and as decorators. It includes a version of contextlib.contextmanager that uses ContextDecorator.
contextdecorator works with Python 2.4+ including Python 3. See the contextdecorator page on PyPI for full details.
contextdecorator is introduced and explained, with examples, in a blog entry.
A XAML writer from reStructured Text source documents
rst2xaml is a script and set of libraries for writing out XAML text markup from ReStructured Text (docutils). It includes a Pygments writer to include highlighted sourcecode (for all the myriad languages Pygments supports) in the output.
XAML is the text markup used by Windows Presentation Foundation (WPF) user interfaces, both for the desktop and for Silverlight / Moonlight web applications. rst2xaml outputs two different varieties of XAML, FlowDocument XAML for WPF and a restricted subset for Silverlight.
rst2xaml itself runs under CPython, but the generated XAML is intended for use from IronPython (or any other .NET language). There is an example IronPython script for displaying the generated XAML using a WPF FlowDocumentReader.
Python Interface to the Akismet API
Version 0.2.0 18th June 2009
Akismet is a web service for recognising spam comments. It promises to be almost 100% effective at catching comment spam. They say that currently 81% of all comments submitted to them are spam.
You'll need a Wordpress Key to use it. This script will allow you to plug akismet into any CGI script or web application. It's extremely easy to use, because the folks at akismet have implemented a nice and straightforward REST API.
As of version 0.2.0 akismet.py can be used with Google AppEngine.
Here's an example of how to use it :
api = Akismet(agent='Test Script')
# if apikey.txt is in place,
# the key will automatically be set
# or you can call ``api.setAPIKey()``
if api.key is None:
print "No 'apikey.txt' file."
elif not api.verify_key():
print "The API key is invalid."
# data should be a dictionary of values
# They can all be filled in with defaults
# from a CGI environment
if api.comment_check(comment, data):
print 'This comment is spam.'
print 'This comment is ham.'
It also comes with an example CGI.
You can read the full docs at :
Download it here :
Prebuilt Python Binaries for Windows
Due to export restrictions prebuilt binaries are not-available from the PyCrypto homepage, so I'm offering Windows installer binaries for download here.
For PyCrypto 2.6.1 binaries, for all versions of Python in 32bit and 64 bit and as wheels, see: PyCrypto 2.6.1.
PyCrypto binaries built by Christian Heimes and sponsored by NSB/AppStudio.
PyCrypto 2.6 (binaries provided by Christian Heimes):
The PyCrypto 2.6 files are all bdist_wininst created with MS Visual Studio 2008 and 2010 (for 3.3). The binaries don't include MPIR / GMP _fastmath.
- PyCrypto 2.6 for Python 2.6 32bit
- PyCrypto 2.6 for Python 2.6 32bit (asc signature)
- PyCrypto 2.6 for Python 2.6 64bit
- PyCrypto 2.6 for Python 2.6 64bit (asc signature)
- PyCrypto 2.6 for Python 2.7 32bit
- PyCrypto 2.6 for Python 2.7 32bit (asc signature)
- PyCrypto 2.6 for Python 2.7 64bit
- PyCrypto 2.6 for Python 2.7 64bit (asc signature)
- PyCrypto 2.6 for Python 3.2 32bit
- PyCrypto 2.6 for Python 3.2 32bit (asc signature)
- PyCrypto 2.6 for Python 3.2 64bit
- PyCrypto 2.6 for Python 3.2 64bit (asc signature)
- PyCrypto 2.6 for Python 3.3 32bit
- PyCrypto 2.6 for Python 3.3 32bit (asc signature)
- PyCrypto 2.6 for Python 3.3 64bit
- PyCrypto 2.6 for Python 3.3 64bit (asc signature)
- PyCrypto 2.3 for 32bit Windows and Python 2.7 (.zip)
- PyCrypto 2.3 for 32bit Windows and Python 2.6 (.zip)
- PyCrypto 2.3 for 32bit Windows and Python 2.5 (.zip)
- PyCrypto 2.3 for 32bit Windows and Python 2.4 (.zip)
- PyCrypto 2.1 for 32bit Windows and Python 2.7 (.zip)
- PyCrypto 2.1 for 32bit Windows and Python 2.6 (.zip)
- PyCrypto 2.1 for 32bit Windows and Python 2.5 (.zip)
- PyCrypto 2.1 for 32bit Windows and Python 2.4 (.zip)
Here are binaries for version 2.0.1 for Python 2.2, 2.3, 2.4, 2.5 and 2.6.
The Python 2.2 and 2.3 binaries are compiled with gcc from MingW32.
The Python 2.4 and 2.5 binaries are compiled using the Microsoft Optimising compiler. As an added bonus, these are windows installers.
The Python 2.6 binary is built with Visual Studio 2008.
Download them here :
- pycrypto-2.0.1.win32-py2.2.zip (147k)
- pycrypto-2.0.1.win32-py2.3.zip (148k)
- pycrypto-2.0.1.win32-py2.4.zip (173k)
- pycrypto-2.0.1.win32-py2.5.zip (173k)
- pycrypto-2.0.1.win32-py2.6.exe (237k)
Additionally, Jeffrey Foran has provided prebuilt AMD64 binaries of version 2.0.1 for Python 2.6:
Prebuilt Python Binaries for Windows
Development of psyco was recently taken over by Christian Tismer. Christian made many improvements to Psyco, but Windows binaries were never released. Available here are compiled binaries of psyco 2 for Windows for Python 2.4, 2.5 and 2.6.
- pysco 2.0.0 for 32bit Windows and Python 2.6 (.zip)
- pysco 2.0.0 for 32bit Windows and Python 2.5 (.zip)
- pysco 2.0.0 for 32bit Windows and Python 2.4 (.zip)
(Compiled from SVN head on January 11th 2010.)
From the official psyco project page on Sourceforge, prebuilt binaries are only available for Python 2.5. Here are binaries for psyco 1.6 for Python 2.4 and 2.6:
Plus binaries for psyco 1.5.1 for Python 2.2 and 2.3:
The installers for Python 2.2 & 2.3 were compiled with MingW32.
For buying techie books, science fiction, computer hardware or the latest gadgets: visit The Voidspace Amazon Store.
Last edited Wed Oct 31 20:50:14 2012.