tempfile

Temporary files.

This module provides generic, low- and high-level interfaces for creating temporary files and directories. All of the interfaces provided by this module can be used without fear of race conditions except for ‘mktemp’. ‘mktemp’ is subject to race conditions and should not be used; it is provided for backward compatibility only.

This module also provides some data items to the user:

TMP_MAX - maximum number of names that will be tried before
giving up.
template - the default prefix for all temporary names.
You may change this to control the default prefix.
tempdir - If this is set to a string before the first use of
any routine from this module, it will be considered as another candidate location to store temporary files.

Functions

NamedTemporaryFile([mode, bufsize, suffix, ...]) Create and return a temporary file.
TemporaryFile([mode, bufsize, suffix, ...]) Create and return a temporary file.
gettempdir() Accessor for tempfile.tempdir.
gettempprefix() Accessor for tempdir.template.
mkdtemp([suffix, prefix, dir]) User-callable function to create and return a unique temporary directory.
mkstemp([suffix, prefix, dir, text]) User-callable function to create and return a unique temporary file.
mktemp([suffix, prefix, dir]) User-callable function to return a unique temporary file name.

Classes

SpooledTemporaryFile([max_size, mode, ...]) Temporary file wrapper, specialized to switch from StringIO to a real file when it exceeds a certain size or when a fileno is needed.