Python Runtime Services¶
The modules described in this chapter provide a wide range of services related to the Python interpreter and its interaction with its environment. Here’s an overview:
sys
— System-specific parameters and functionsabiflags
addaudithook()
argv
audit()
base_exec_prefix
base_prefix
byteorder
builtin_module_names
call_tracing()
copyright
_clear_type_cache()
_current_frames()
_current_exceptions()
breakpointhook()
_debugmallocstats()
dllhandle
displayhook()
dont_write_bytecode
_emscripten_info
pycache_prefix
excepthook()
__breakpointhook__
__displayhook__
__excepthook__
__unraisablehook__
exception()
exc_info()
exec_prefix
executable
exit()
flags
float_info
float_repr_style
getallocatedblocks()
getandroidapilevel()
getdefaultencoding()
getdlopenflags()
getfilesystemencoding()
getfilesystemencodeerrors()
get_int_max_str_digits()
getrefcount()
getrecursionlimit()
getsizeof()
getswitchinterval()
_getframe()
getprofile()
gettrace()
getwindowsversion()
get_asyncgen_hooks()
get_coroutine_origin_tracking_depth()
hash_info
hexversion
implementation
int_info
__interactivehook__
intern()
is_finalizing()
last_type
last_value
last_traceback
maxsize
maxunicode
meta_path
modules
orig_argv
path
path_hooks
path_importer_cache
platform
platlibdir
prefix
ps1
ps2
setdlopenflags()
set_int_max_str_digits()
setprofile()
setrecursionlimit()
setswitchinterval()
settrace()
set_asyncgen_hooks()
set_coroutine_origin_tracking_depth()
_enablelegacywindowsfsencoding()
stdin
stdout
stderr
__stdin__
__stdout__
__stderr__
stdlib_module_names
thread_info
tracebacklimit
unraisablehook()
version
api_version
version_info
warnoptions
winver
_xoptions
sysconfig
— Provide access to Python’s configuration informationbuiltins
— Built-in objects__main__
— Top-level code environmentwarnings
— Warning controldataclasses
— Data Classescontextlib
— Utilities forwith
-statement contexts- Utilities
- Examples and Recipes
- Single use, reusable and reentrant context managers
abc
— Abstract Base Classesatexit
— Exit handlerstraceback
— Print or retrieve a stack tracebackprint_tb()
print_exception()
print_exc()
print_last()
print_stack()
extract_tb()
extract_stack()
format_list()
format_exception_only()
format_exception()
format_exc()
format_tb()
format_stack()
clear_frames()
walk_stack()
walk_tb()
TracebackException
ObjectsTracebackException
TracebackException.__cause__
TracebackException.__context__
TracebackException.__suppress_context__
TracebackException.__notes__
TracebackException.stack
TracebackException.exc_type
TracebackException.filename
TracebackException.lineno
TracebackException.text
TracebackException.offset
TracebackException.msg
TracebackException.from_exception()
TracebackException.print()
TracebackException.format()
TracebackException.format_exception_only()
StackSummary
ObjectsFrameSummary
Objects- Traceback Examples
__future__
— Future statement definitionsgc
— Garbage Collector interfaceenable()
disable()
isenabled()
collect()
set_debug()
get_debug()
get_objects()
get_stats()
set_threshold()
get_count()
get_threshold()
get_referrers()
get_referents()
is_tracked()
is_finalized()
freeze()
unfreeze()
get_freeze_count()
garbage
callbacks
DEBUG_STATS
DEBUG_COLLECTABLE
DEBUG_UNCOLLECTABLE
DEBUG_SAVEALL
DEBUG_LEAK
inspect
— Inspect live objects- Types and members
getmembers()
getmembers_static()
getmodulename()
ismodule()
isclass()
ismethod()
isfunction()
isgeneratorfunction()
isgenerator()
iscoroutinefunction()
iscoroutine()
isawaitable()
isasyncgenfunction()
isasyncgen()
istraceback()
isframe()
iscode()
isbuiltin()
ismethodwrapper()
isroutine()
isabstract()
ismethoddescriptor()
isdatadescriptor()
isgetsetdescriptor()
ismemberdescriptor()
- Retrieving source code
- Introspecting callables with the Signature object
- Classes and functions
- The interpreter stack
- Fetching attributes statically
- Current State of Generators and Coroutines
- Code Objects Bit Flags
- Command Line Interface
- Types and members
site
— Site-specific configuration hook