The Voidspace Python Modules

The Pythonian Knot

 

 

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
ConfigObj mock
discover akismet
Pythonutils PyCrypto
psyco  
   

ConfigObj

Reading and Writing Config Files

Version 4.6.0 13th April 2009

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

  • List Values

  • 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.

There is an article on using ConfigObj for Data Persistence. The associated module is ConfigPersist. This includes tools for automatically generating 'configspecs' for use with the validate module.

The Mock Library

A Simple Class for Mocking in Unit Tests

Version 0.4.0 12th October 2008

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.

This approach is inspired by the testing patterns used at Resolver Systems.

It also provides utility functions / objects to assist with testing, particularly monkey patching.

discover

Automatic Test Discovery for unittest

Test discovery allows you to run all the unittest based tests (or just a subset of them) in your project without you having to write your own test collection or running machinery. Once installed, test discovery can be invoked with python -m discover. The discover module works with Python 2.4 and more recent, including Python 3.0.

The discover module also implements the load_tests protocol which allows you to customize test loading from modules and packages. Test discovery and load_tests are implemented in the DiscoveringTestLoader which can be used from your own test framework.

See the discover page on PyPI for full details.

Akismet

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.

It's designed to work with the Wordpress Blog Tool, but it's not restricted to that - so this is a Python interface to the Akismet API.

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.

Note

As of version 0.2.0 akismet.py can be used with Google AppEngine.

Here's an example of how to use it :

from akismet import Akismet
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."
else:
    # 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.'
    else:
        print 'This comment is ham.'

It also comes with an example CGI.

You can read the full docs at :

Download it here :

PythonUtils Package

The Voidspace Pythonutils Package

Version 0.4.0 9th June 2009

The Voidspace Pythonutils package is collection of general utility modules that simplify common programming tasks in Python.

The modules included are all fully documented. They are :

  • ConfigObj 4.6.0 - Easy config file reading/writing
  • validate 1.0.0 - Validation and type conversion system
  • StandOut 3.0.0 - Simple logging and output control object
  • pathutils 0.2.6 - For working with paths and files
  • cgiutils 0.3.6 - CGI helpers
  • urlpath 0.1.0 - Functions for handling URLs
  • odict 0.2.2 - Ordered Dictionary Class

Visit the Pythonutils Package Page, or download it directly :

Pythonutils is a pure Python distribution.

PyCrypto 2.0.1

Prebuilt Python Binaries

Windows Binaries

Due to export restrictions Andrew Kuchling is unable to offer prebuilt binaries for his fantastic PyCrypto module.

Here are binaries for Python 2.2, 2.3, 2.4 and 2.5.

The Python 2.2 and 2.3 binaries are compiled with gcc from MingW32 [1].

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 :

Additionally, Jeffrey Foran has provided prebuilt AMD64 binaries for Python 2.6:

psyco

Compiled Binaries

Windows Installers

As you probably know psyco is the Python specializing compiler, created by Armin Rigo who is now working on PyPy. psyco speeds up the execution of most Python programs with a single extension module.

Prebuilt binaries are only available from sourceforge for Python 2.4. Here are binaries for the missing versions from Python 2.2 and 2.3. These are for psyco 1.5.1. Smile

Download them here :

The installers for Python 2.2 & 2.3 were compiled with MingW32.

I've also built a binary version of psyco 1.6 for Python 2.6 (built with Visual Studio 2008):

[1]Done by following the instructions at Building Python Extensions Using MingW32.

For buying techie books, science fiction, computer hardware or the latest gadgets: visit The Voidspace Amazon Store. If you're looking for a new techie job, try the Voidspace Tech Job Board. This is part of the Hidden Network of technology and programming jobs.

Hosted by Webfaction

Return to Top

Page rendered with rest2web the Site Builder

Last edited Wed Jun 24 23:23:50 2009.

Counter...