PyDocs

Python Runtime Services

sys

This module provides access to some objects used or maintained by the
interpreter and to functions that interact strongly with the interpreter.

Dynamic objects:

argv -- command line arguments; argv[0] is the script pathname if known
path -- module search path; path[0] is the script directory, else ''
modules -- dictionary of loaded modules

displayhook -- called to show results in an interactive session
excepthook -- called to handle any uncaught exception other than SystemExit
  To customize printing in an interactive session or to install a custom
  top-level exception handler, assign other functions to replace these.

stdin -- standard input file object; used by input()
stdout -- standard output file object; used by print()
stderr -- standard error object; used for error messages
  By assigning other file objects (or objects that behave like files)
  to these, it is possible to redirect all of the interpreter's I/O.

last_exc - the last uncaught exception
  Only available in an interactive session after a
  traceback has been printed.
last_type -- type of last uncaught exception
last_value -- value of last uncaught exception
last_traceback -- traceback of last uncaught exception
  These three are the (deprecated) legacy representation of last_exc.

Static objects:

abi_info -- Python ABI information.
builtin_module_names -- tuple of module names built into this interpreter
copyright -- copyright notice pertaining to this interpreter
exec_prefix -- prefix used to find the machine-specific Python library
executable -- absolute path of the executable binary of the Python interpreter
float_info -- a named tuple with information about the float implementation.
float_repr_style -- string indicating the style of repr() output for floats
hash_info -- a named tuple with information about the hash algorithm.
hexversion -- version information encoded as a single integer
implementation -- Python implementation information.
int_info -- a named tuple with information about the int implementation.
maxsize -- the largest supported length of containers.
maxunicode -- the value of the largest Unicode code point
platform -- platform identifier
prefix -- prefix used to find the Python library
thread_info -- a named tuple with information about the thread implementation.
version -- the version of this interpreter as a string
version_info -- version information as a named tuple
__stdin__ -- the original stdin; don't touch!
__stdout__ -- the original stdout; don't touch!
__stderr__ -- the original stderr; don't touch!
__displayhook__ -- the original displayhook; don't touch!
__excepthook__ -- the original excepthook; don't touch!

Functions:

displayhook() -- print an object to the screen, and save it in builtins._
excepthook() -- print an exception and its traceback to sys.stderr
exception() -- return the current thread's active exception
exc_info() -- return information about the current thread's active exception
exit() -- exit the interpreter by raising SystemExit
getdlopenflags() -- returns flags to be used for dlopen() calls
getprofile() -- get the global profiling function
getrefcount() -- return the reference count for an object (plus one :-)
getrecursionlimit() -- return the max recursion depth for the interpreter
getsizeof() -- return the size of an object in bytes
gettrace() -- get the global debug tracing function
setdlopenflags() -- set the flags to be used for dlopen() calls
setprofile() -- set the global profiling function
setrecursionlimit() -- set the max recursion depth for the interpreter
settrace() -- set the global debug tracing function
Symbols in sys

_

__breakpointhook__
This hook function is called by built-in breakpoint().
__displayhook__
Print an object to sys.stdout and also save it in builtins._
__excepthook__
Handle an exception by displaying it with a traceback on sys.stderr.
__interactivehook__
Configure readline completion on interactive prompts.
__stderr__
These objects contain the original values of stdin, stderr and stdout at the start of the program.
__stdin__
These objects contain the original values of stdin, stderr and stdout at the start of the program.
__stdout__
These objects contain the original values of stdin, stderr and stdout at the start of the program.
__unraisablehook__
Handle an unraisable exception.
_clear_internal_caches
Clear all internal performance-related caches.
_clear_type_cache
Clear the internal type lookup cache.
_current_exceptions
Return a dict mapping each thread's identifier to its current raised exception.
_current_frames
Return a dict mapping each thread's thread id to its current stack frame.
_debugmallocstats
Print summary info to stderr about the state of pymalloc's structures.
_emscripten_info
A named tuple holding information about the environment on the wasm32-emscripten platform.
_enablelegacywindowsfsencoding
Changes the filesystem encoding and error handler to ‘mbcs’ and ‘replace’ respectively, for consistency with versions of Python prior to 3.6.
_getframe
Return a frame object from the call stack.
_getframemodulename
Return the name of the module for a calling frame.
_is_gil_enabled
Return True if the GIL is currently enabled and False otherwise.
_is_immortal
Return True if the given object is "immortal" per PEP 683.
_is_interned
Return True if the given string is "interned".
_jit
Utilities for observing just-in-time compilation.
_xoptions
A dictionary of the various implementation-specific flags passed through the -X command-line option.

a

abi_info
An object containing information about the ABI of the currently running Python interpreter.
abiflags
On POSIX systems where Python was built with the standard configure script, this contains the ABI flags as specified by PEP 3149.
activate_stack_trampoline
Activate stack profiler trampoline *backend*.
addaudithook
Adds a new audit hook callback.
api_version
The C API version, equivalent to the C macro PYTHON_API_VERSION.
argv
The list of command line arguments passed to a Python script.
audit
Passes the event to any audit hooks that are attached.

b

base_exec_prefix
Equivalent to exec_prefix, but referring to the base Python installation.
base_prefix
Equivalent to prefix, but referring to the base Python installation.
breakpointhook
This hook function is called by built-in breakpoint().
builtin_module_names
A tuple of strings containing the names of all modules that are compiled into this Python interpreter.
byteorder
An indicator of the native byte order.

c

call_tracing
Call func(*args), while tracing is enabled.
copyright
A string containing the copyright pertaining to the Python interpreter.

d

deactivate_stack_trampoline
Deactivate the current stack profiler trampoline backend.
displayhook
Print an object to sys.stdout and also save it in builtins._
dllhandle
Integer specifying the handle of the Python DLL.
dont_write_bytecode
If this is true, Python won’t try to write .pyc files on the import of source modules.

e

exc_info
Return current exception information: (type, value, traceback).
excepthook
Handle an exception by displaying it with a traceback on sys.stderr.
exception
Return the current exception.
exec_prefix
A string giving the site-specific directory prefix where the platform-dependent Python files are installed; by default, this is also '/usr/local'.
executable
A string giving the absolute path of the executable binary for the Python interpreter, on systems where this makes sense.
exit
Exit the interpreter by raising SystemExit(status).

f

flags
The named tuple flags exposes the status of command line flags.
float_info
A named tuple holding information about the float type.
float_repr_style
A string indicating how the repr() function behaves for floats.

g

get_asyncgen_hooks
Return the installed asynchronous generators hooks.
get_coroutine_origin_tracking_depth
Check status of origin tracking for coroutine objects in this thread.
get_int_max_str_digits
Return the maximum string digits limit for non-binary int<->str conversions.
get_lazy_imports
Gets the global lazy imports mode.
get_lazy_imports_filter
Get the current lazy imports filter callback.
getallocatedblocks
Return the number of memory blocks currently allocated.
getandroidapilevel
Return the build-time API level of Android as an integer.
getdefaultencoding
Return the current default encoding used by the Unicode implementation.
getdlopenflags
Return the current value of the flags that are used for dlopen calls.
getfilesystemencodeerrors
Return the error mode used Unicode to OS filename conversion.
getfilesystemencoding
Return the encoding used to convert Unicode filenames to OS filenames.
getobjects
This function only exists if CPython was built using the specialized configure option --with-trace-refs.
getprofile
Return the profiling function set with sys.setprofile.
getrecursionlimit
Return the current value of the recursion limit.
getrefcount
Return the reference count of object.
getsizeof
Return the size of object in bytes.
getswitchinterval
Return the current thread switch interval; see sys.setswitchinterval().
gettrace
Return the global debug tracing function set with sys.settrace.
getunicodeinternedsize
Return the number of elements of the unicode interned dictionary
getwindowsversion
Return a named tuple describing the Windows version currently running.

h

hash_info
A named tuple giving parameters of the numeric hash implementation.
hexversion
The version number encoded as a single integer.

i

implementation
An object containing information about the implementation of the currently running Python interpreter.
int_info
A named tuple that holds information about Python’s internal representation of integers.
intern
``Intern'' the given string.
is_finalizing
Return True if Python is exiting.
is_stack_trampoline_active
Return *True* if a stack profiler trampoline is active.

l

last_exc
This variable is not always defined; it is set to the exception instance when an exception is not handled and the interpreter prints an error message and a stack traceback.
last_traceback
These three variables are deprecated; use sys.last_exc instead.
last_type
These three variables are deprecated; use sys.last_exc instead.
last_value
These three variables are deprecated; use sys.last_exc instead.
lazy_modules
A set of fully qualified module name strings that have been lazily imported in the current interpreter but not yet loaded.

m

maxsize
An integer giving the maximum value a variable of type Py_ssize_t can take.
maxunicode
An integer giving the value of the largest Unicode code point, i.e.
meta_path
A list of meta path finder objects that have their find_spec() methods called to see if one of the objects can find the module to be imported.
modules
This is a dictionary that maps module names to modules which have already been loaded.

o

orig_argv
The list of the original command line arguments passed to the Python executable.

p

path
A list of strings that specifies the search path for modules.
path_hooks
A list of callables that take a path argument to try to create a finder for the path.
path_importer_cache
A dictionary acting as a cache for finder objects.
platform
A string containing a platform identifier.
platlibdir
Name of the platform-specific library directory.
prefix
A string giving the site-specific directory prefix where the platform independent Python files are installed; on Unix, the default is /usr/local.
ps1
Strings specifying the primary and secondary prompt of the interpreter.
ps2
Strings specifying the primary and secondary prompt of the interpreter.
pycache_prefix
If this is set (not None), Python will write bytecode-cache .pyc files to (and read them from) a parallel directory tree rooted at this directory, rather than from __pycache__ directories in the sour…

r

remote_exec
Executes a file containing Python code in a given remote Python process.

s

set_asyncgen_hooks
Set a finalizer for async generators objects.
set_coroutine_origin_tracking_depth
Enable or disable origin tracking for coroutine objects in this thread.
set_int_max_str_digits
Set the maximum string digits limit for non-binary int<->str conversions.
set_lazy_imports
Sets the global lazy imports mode.
set_lazy_imports_filter
Set the lazy imports filter callback.
setdlopenflags
Set the flags used by the interpreter for dlopen calls.
setprofile
Set the profiling function.
setrecursionlimit
Set the maximum depth of the Python interpreter stack to n.
setswitchinterval
Set the ideal thread switching delay inside the Python interpreter.
settrace
Set the global debug tracing function.
stderr
File objects used by the interpreter for standard input, output and errors:
stdin
File objects used by the interpreter for standard input, output and errors:
stdlib_module_names
A frozenset of strings containing the names of standard library modules.
stdout
File objects used by the interpreter for standard input, output and errors:

t

thread_info
A named tuple holding information about the thread implementation.
tracebacklimit
When this variable is set to an integer value, it determines the maximum number of levels of traceback information printed when an unhandled exception occurs.

u

unraisablehook
Handle an unraisable exception.

v

version
A string containing the version number of the Python interpreter plus additional information on the build number and compiler used.
version_info
A tuple containing the five components of the version number: major, minor, micro, releaselevel, and serial.

w

warnoptions
This is an implementation detail of the warnings framework; do not modify this value.
winver
The version number used to form registry keys on Windows platforms.