Saving a figure to StringIO or similar

I am writing a web server app that creates charts among other things. I am trying to get rid of the temporary file that I use to transmit the figures created with matplotlib to the actual web server. Although print_figure says "If filename is a fileobject, write png to file object (thus you can, for example, write the png to stdout)" I can't successfully write anything to stdout. Anyone knows an example or can give me some hint what I can do to get rid of the tempfile?

Thanks,
Sascha