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 functionsabiflagsaddaudithook()argvaudit()base_exec_prefixbase_prefixbyteorderbuiltin_module_namescall_tracing()copyright_clear_type_cache()_current_frames()_current_exceptions()breakpointhook()_debugmallocstats()dllhandledisplayhook()dont_write_bytecode_emscripten_infopycache_prefixexcepthook()__breakpointhook____displayhook____excepthook____unraisablehook__exception()exc_info()exec_prefixexecutableexit()flagsfloat_infofloat_repr_stylegetallocatedblocks()getunicodeinternedsize()getandroidapilevel()getdefaultencoding()getdlopenflags()getfilesystemencoding()getfilesystemencodeerrors()get_int_max_str_digits()getrefcount()getrecursionlimit()getsizeof()getswitchinterval()_getframe()_getframemodulename()getprofile()gettrace()getwindowsversion()get_asyncgen_hooks()get_coroutine_origin_tracking_depth()hash_infohexversionimplementationint_info__interactivehook__intern()is_finalizing()last_exclast_typelast_valuelast_tracebackmaxsizemaxunicodemeta_pathmodulesorig_argvpathpath_hookspath_importer_cacheplatformplatlibdirprefixps1ps2setdlopenflags()set_int_max_str_digits()setprofile()setrecursionlimit()setswitchinterval()settrace()set_asyncgen_hooks()set_coroutine_origin_tracking_depth()activate_stack_trampoline()deactivate_stack_trampoline()is_stack_trampoline_active()_enablelegacywindowsfsencoding()stdinstdoutstderr__stdin____stdout____stderr__stdlib_module_namesthread_infotracebacklimitunraisablehook()versionapi_versionversion_infowarnoptionswinver_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()TracebackExceptionObjectsTracebackExceptionTracebackException.__cause__TracebackException.__context__TracebackException.exceptionsTracebackException.__suppress_context__TracebackException.__notes__TracebackException.stackTracebackException.exc_typeTracebackException.filenameTracebackException.linenoTracebackException.end_linenoTracebackException.textTracebackException.offsetTracebackException.end_offsetTracebackException.msgTracebackException.from_exception()TracebackException.print()TracebackException.format()TracebackException.format_exception_only()
StackSummaryObjectsFrameSummaryObjects- 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()garbagecallbacksDEBUG_STATSDEBUG_COLLECTABLEDEBUG_UNCOLLECTABLEDEBUG_SAVEALLDEBUG_LEAK
inspect— Inspect live objects- Types and members
getmembers()getmembers_static()getmodulename()ismodule()isclass()ismethod()isfunction()isgeneratorfunction()isgenerator()iscoroutinefunction()markcoroutinefunction()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, Coroutines, and Asynchronous Generators
- Code Objects Bit Flags
- Buffer flags
BufferFlagsBufferFlags.SIMPLEBufferFlags.WRITABLEBufferFlags.FORMATBufferFlags.NDBufferFlags.STRIDESBufferFlags.C_CONTIGUOUSBufferFlags.F_CONTIGUOUSBufferFlags.ANY_CONTIGUOUSBufferFlags.INDIRECTBufferFlags.CONTIGBufferFlags.CONTIG_ROBufferFlags.STRIDEDBufferFlags.STRIDED_ROBufferFlags.RECORDSBufferFlags.RECORDS_ROBufferFlags.FULLBufferFlags.FULL_ROBufferFlags.READBufferFlags.WRITE
- Command Line Interface
- Types and members
site— Site-specific configuration hook