import tempfile
import shutil

tmpdir = tempfile.mkdtemp()
# ...
shutil.rmtree(tmpdir)