I was looking for a pure-Python library to generate a MIDI file, mxm's Python MIDI library is exactly that.
From this dzone snippet, there is a single-file version of the above library, smidi.py (gist'd here for posterity)
Usage is quite simple:
>>> import smidi
>>> m = smidi.MidiOutFile('out.mid')
>>> m.header()
>>> m.start_of_track()
>>> m.update_time(0)
>>> m.note_on(note=0x40) # single note
>>> m.update_time(192)
>>> m.note_off(note=0x40) # stop it after 192
>>> m.update_time(0)
>>> m.end_of_track()
>>> m.eof()
Presumably works on Windows (as the original example uses C:\out.mid
as the output filename), and I've tested it on OS X