Commonly I create temporary files using dd like this:
dd if=/dev/random of=blah bs=1m count=16
That will generate a random 16MB file named blah.
Doing the same thing in python looks something like this:
Posting here because it took me about 15 minutes longer than it should have to find that function.