There are 2 repositories under midifile topic.
MIDI Objects for Python
perl based standard midi file generator