The Voidspace Python Modules

The Pythonian Knot

 

 

Loading ...

 

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

PythonUtils Package

The Voidspace Pythonutils Package

Version 0.3.0 22nd April 2007

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.4.0 - Easy config file reading/writing
  • validate 0.2.3 - Validation and type conversion system
  • StandOut 3.0.0 - Simple logging and output control object
  • pathutils 0.2.5 - For working with paths and files
  • cgiutils 0.3.5 - 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 :

The documentation is included in pythonutils-0.3.0.zip, but not in the windows executable. Pythonutils is a pure Python distribution.

ConfigObj

Reading and Writing Config Files

Version 4.5.2 24th February 2008

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 :

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.

Ordered Dictionary

Keeping Things in Order

Version 0.2.2 25th November 2006

This module contains a class called OrderedDict. It is written by Nicola Larosa in collaboration with Michael Foord. The ordered dictionary is a dictionary like object (actually a subclass of the normal dictionary data-type) that keeps keys in insertion order.

This means it has all the normal dictionary methods. Methods that would normally return values in an arbitrary order are now ordered. You can alter the order through the setkeys method.

Because these dictionaries are ordered, they also have several sequence methods. These include index, insert, reverse, and sort.

Additionally, there is a class called SequenceOrderedDict. This has custom sequence objects that replace the keys, values, and items methods. They are callable - so they behave exactly the methods. You can also manipulate them directly as sequences.

Download links :

This version of the ordered dictionary replaces the previous version which was actually a sorted dictionary. This one is better.

The Mock Library

A Simple Class for Mocking in Unit Tests

Version 0.3.1 3rd December 2007

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.

Akismet

Python Interface to the Akismet API

Version 0.1.5 5th February 2007

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.

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 :

StandOut

Logging and Control for sys.stdout and sys.stderr

Version 3.0.0 28th August 2006

StandOut is a simple way of adding varying levels of verbosity to your program and to allow logging to a file: using just the normal print command.

You set a verbosity level (or your user can, from the command line for example), and only messages with a priority greater than that setting are displayed. You can set the general priority levels, or specify an explicit priority for individual messages.

You can set the threshold level for the log file to be the same, or different. Very easy to use and saves having seperate code to maintain a log or determine message priority.

It will divert sys.stdout and / or stderr and can log them both to the same file.

See the StandOut Homepage.

Download it here :

dataenc

Date and Password Stamping

Version 1.1.5 13th September 2004

A pure python module for combining data using a 'binary interleave' - two pieces of data are woven together a bit at a time, making them unrecognisable in the process. Another function reverses the process. A table encoding can be used to turn the resulting binary string into an ascii string. Useful for encoding passwords/timestamping into cookies or html form fields. This provides a simple mechanism for secure, time limited, logins when writing CGIs. Because the password (or more likely the SHA hash) is timestamped, even if extracted it can only be used for a very limited time.

The binary interleave functions can be used for combining, 'watermarking', or timestamping any data. The binary to ascii function like the binascii module - but the mapping is user definable.

Browse the docs here .

Download it here :

FSDM and Filestruct

Objects for Representing and Comparing File Structures

Version 1.0.4 05th July 2004

This module is written for Dirwatcher, which is an offline directory sync utility. I wrote it because I work on various projects at home and at work. My home computer is not online. This means I often have to copy folders between work and home. Some of these folders get quite sizeable and it would be nice to just transfer the new/modified files, plus a list of any changes...

filestruct is a module for describing file structures and changes to file structures; using a basic markup - that I call FSDM.

This could also form the basis of (for example) an incremental archive, a version control system etc. In fact anything where changes to a file system need to be monitored, or described and changes stored. filestruct.py also works as a command line tool for copying and restoring changes - but for a more convenient, cross-platform GUI see Dirwatcher.

Download it here :

Textmacros

Textmacros for docutils

The textmacros module is a part of Firedrop2. It is also very useful for any program that generates HTML output - like docutils.

This module lets you easily add smilies, Python source colouring, acronyms, and more, to docutils.

See the textmacros homepage.

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.

Download them here :

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 through to Python 2.5. These are for psyco 1.5.1, which at the time of writing [2] is the most recently released version. If you spot a more recent version in the wild, let me know. Smile

Download them here :

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

The installer for Python 2.4 was compiled with the Microsoft optimising compiler.

[1]Done by following the instructions at Building Python Extensions Using MingW32.
[2]August 7th, 2006.

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 Sun Feb 24 20:41:11 2008.


Counter...


Voidspace: Cyberpunk, Technology, Fiction and More
Search this Site:
 
Web Site

IronPython in ActionIronPython in Action

Blogads

Follow me on:

Twitter

Pownce

Jaiku

Del.icio.us

Shared Feeds

Tech Jobs

Hidden Network

Tech Jobs Board

Hosting for an agile web