PyDocs

File and Directory Access

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.

The default path names are returned as str.  If you supply bytes as
input, all return values will be in bytes.  Ex:

    >>> tempfile.mkstemp()
    (4, '/tmp/tmptpu9nin8')
    >>> tempfile.mkdtemp(suffix=b'')
    b'/tmp/tmppbi8f0hy'

This module also provides some data items to the user:

  TMP_MAX  - maximum number of names that will be tried before
             giving up.
  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.
Symbols in tempfile

g

gettempdir
Returns tempfile.tempdir as str.
gettempdirb
Returns tempfile.tempdir as bytes.
gettempprefix
The default prefix for temporary directories as string.
gettempprefixb
The default prefix for temporary directories as bytes.

m

mkdtemp
User-callable function to create and return a unique temporary directory.
mkstemp
User-callable function to create and return a unique temporary file.
mktemp
User-callable function to return a unique temporary file name.

n

NamedTemporaryFile
Create and return a temporary file.

s

SpooledTemporaryFile
Temporary file wrapper, specialized to switch from BytesIO or StringIO to a real file when it exceeds a certain size or when a fileno is needed.

t

tempdir
When set to a value other than None, this variable defines the default value for the dir argument to the functions defined in this module, including its type, bytes or str.
TemporaryDirectory
Create and return a temporary directory.
TemporaryFile
Create and return a temporary file.