importlib API Reference

Full documentation for importlib (Standard Library / Native)

importlib.import_module
Python Library Documentation: function import_module in module importlib

import_module(name, package=None)
    Import a module.

    The 'package' argument is required when performing a relative import. It
    specifies the package to use as the anchor point from which to resolve the
    relative import to an absolute import.
importlib.invalidate_caches
Python Library Documentation: function invalidate_caches in module importlib

invalidate_caches()
    Call the invalidate_caches() method on all meta path finders stored in
    sys.meta_path (where implemented).
importlib.machinery
Python Library Documentation: module importlib.machinery in importlib

NAME
    importlib.machinery - The machinery of importlib: finders, loaders, hooks, etc.

MODULE REFERENCE
    https://docs.python.org/3.12/library/importlib.machinery.html

    The following documentation is automatically generated from the Python
    source files.  It may be incomplete, incorrect or include features that
    are considered implementation detail and may vary between Python
    implementations.  When in doubt, consult the module reference at the
    location listed above.

FUNCTIONS
    all_suffixes()
        Returns a list of all recognized module suffixes for this process

DATA
    BYTECODE_SUFFIXES = ['.pyc']
    DEBUG_BYTECODE_SUFFIXES = ['.pyc']
    EXTENSION_SUFFIXES = ['.cp312-win_amd64.pyd', '.pyd']
    OPTIMIZED_BYTECODE_SUFFIXES = ['.pyc']
    SOURCE_SUFFIXES = ['.py', '.pyw']

FILE
    c:\users\youse\appdata\local\programs\python\python312\lib\importlib\machinery.py

importlib.reload
Python Library Documentation: function reload in module importlib

reload(module)
    Reload the module and return it.

    The module must have been successfully imported before.
importlib.sys
Python Library Documentation: built-in module sys

NAME
    sys

MODULE REFERENCE
    https://docs.python.org/3.12/library/sys.html

    The following documentation is automatically generated from the Python
    source files.  It may be incomplete, incorrect or include features that
    are considered implementation detail and may vary between Python
    implementations.  When in doubt, consult the module reference at the
    location listed above.

DESCRIPTION
    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:

    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
    dllhandle -- [Windows only] integer handle of the Python DLL
    winver -- [Windows only] version number of the Python DLL
    _enablelegacywindowsfsencoding -- [Windows only]
    __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

SUBMODULES
    monitoring

FUNCTIONS
    __breakpointhook__ = breakpointhook(...)
        breakpointhook(*args, **kws)

        This hook function is called by built-in breakpoint().

    __displayhook__ = displayhook(object, /)
        Print an object to sys.stdout and also save it in builtins._

    __excepthook__ = excepthook(exctype, value, traceback, /)
        Handle an exception by displaying it with a traceback on sys.stderr.

    __unraisablehook__ = unraisablehook(unraisable, /)
        Handle an unraisable exception.

        The unraisable argument has the following attributes:

        * exc_type: Exception type.
        * exc_value: Exception value, can be None.
        * exc_traceback: Exception traceback, can be None.
        * err_msg: Error message, can be None.
        * object: Object causing the exception, can be None.

    activate_stack_trampoline(backend, /)
        Activate stack profiler trampoline *backend*.

    addaudithook(hook)
        Adds a new audit hook callback.

    audit(...)
        audit(event, *args)

        Passes the event to any audit hooks that are attached.

    breakpointhook(...)
        breakpointhook(*args, **kws)

        This hook function is called by built-in breakpoint().

    call_tracing(func, args, /)
        Call func(*args), while tracing is enabled.

        The tracing state is saved, and restored afterwards.  This is intended
        to be called from a debugger from a checkpoint, to recursively debug
        some other code.

    deactivate_stack_trampoline()
        Deactivate the current stack profiler trampoline backend.

        If no stack profiler is activated, this function has no effect.

    displayhook(object, /)
        Print an object to sys.stdout and also save it in builtins._

    exc_info()
        Return current exception information: (type, value, traceback).

        Return information about the most recent exception caught by an except
        clause in the current stack frame or in an older stack frame.

    excepthook(exctype, value, traceback, /)
        Handle an exception by displaying it with a traceback on sys.stderr.

    exception()
        Return the current exception.

        Return the most recent exception caught by an except clause
        in the current stack frame or in an older stack frame, or None
        if no such exception exists.

    exit(status=None, /)
        Exit the interpreter by raising SystemExit(status).

        If the status is omitted or None, it defaults to zero (i.e., success).
        If the status is an integer, it will be used as the system exit status.
        If it is another kind of object, it will be printed and the system
        exit status will be one (i.e., failure).

    get_asyncgen_hooks()
        Return the installed asynchronous generators hooks.

        This returns a namedtuple of the form (firstiter, finalizer).

    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.

    getallocatedblocks()
        Return the number of memory blocks currently allocated.

    getdefaultencoding()
        Return the current default encoding used by the Unicode implementation.

    getfilesystemencodeerrors()
        Return the error mode used Unicode to OS filename conversion.

    getfilesystemencoding()
        Return the encoding used to convert Unicode filenames to OS filenames.

    getprofile()
        Return the profiling function set with sys.setprofile.

        See the profiler chapter in the library manual.

    getrecursionlimit()
        Return the current value of the recursion limit.

        The recursion limit is the maximum depth of the Python interpreter
        stack.  This limit prevents infinite recursion from causing an overflow
        of the C stack and crashing Python.

    getrefcount(object, /)
        Return the reference count of object.

        The count returned is generally one higher than you might expect,
        because it includes the (temporary) reference as an argument to
        getrefcount().

    getsizeof(...)
        getsizeof(object [, default]) -> int

        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.

        See the debugger chapter in the library manual.

    getunicodeinternedsize()
        Return the number of elements of the unicode interned dictionary

    getwindowsversion()
        Return info about the running version of Windows as a named tuple.

        The members are named: major, minor, build, platform, service_pack,
        service_pack_major, service_pack_minor, suite_mask, product_type and
        platform_version. For backward compatibility, only the first 5 items
        are available by indexing. All elements are numbers, except
        service_pack and platform_type which are strings, and platform_version
        which is a 3-tuple. Platform is always 2. Product_type may be 1 for a
        workstation, 2 for a domain controller, 3 for a server.
        Platform_version is a 3-tuple containing a version number that is
        intended for identifying the OS rather than feature detection.

    intern(string, /)
        ``Intern'' the given string.

        This enters the string in the (global) table of interned strings whose
        purpose is to speed up dictionary lookups. Return the string itself or
        the previously interned string object with the same value.

    is_finalizing()
        Return True if Python is exiting.

    is_stack_trampoline_active()
        Return *True* if a stack profiler trampoline is active.

    set_asyncgen_hooks(...)
        set_asyncgen_hooks([firstiter] [, finalizer])

        Set a finalizer for async generators objects.

    set_coroutine_origin_tracking_depth(depth)
        Enable or disable origin tracking for coroutine objects in this thread.

        Coroutine objects will track 'depth' frames of traceback information
        about where they came from, available in their cr_origin attribute.

        Set a depth of 0 to disable.

    set_int_max_str_digits(maxdigits)
        Set the maximum string digits limit for non-binary int<->str conversions.

    setprofile(...)
        setprofile(function)

        Set the profiling function.  It will be called on each function call
        and return.  See the profiler chapter in the library manual.

    setrecursionlimit(limit, /)
        Set the maximum depth of the Python interpreter stack to n.

        This limit prevents infinite recursion from causing an overflow of the C
        stack and crashing Python.  The highest possible limit is platform-
        dependent.

    setswitchinterval(interval, /)
        Set the ideal thread switching delay inside the Python interpreter.

        The actual frequency of switching threads can be lower if the
        interpreter executes long sequences of uninterruptible code
        (this is implementation-specific and workload-dependent).

        The parameter must represent the desired switching delay in seconds
        A typical value is 0.005 (5 milliseconds).

    settrace(...)
        settrace(function)

        Set the global debug tracing function.  It will be called on each
        function call.  See the debugger chapter in the library manual.

    unraisablehook(unraisable, /)
        Handle an unraisable exception.

        The unraisable argument has the following attributes:

        * exc_type: Exception type.
        * exc_value: Exception value, can be None.
        * exc_traceback: Exception traceback, can be None.
        * err_msg: Error message, can be None.
        * object: Object causing the exception, can be None.

DATA
    __stderr__ = <_io.TextIOWrapper name='<stderr>' mode='w' encoding='cp1...
    __stdin__ = <_io.TextIOWrapper name='<stdin>' mode='r' encoding='utf-8...
    __stdout__ = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='cp1...
    api_version = 1013
    argv = [r'f:\JoeyCodes\PyDocs\py_docs.py', '--worker', 'importlib', r'...
    base_exec_prefix = r'C:\Users\Youse\AppData\Local\Programs\Python\Pyth...
    base_prefix = r'C:\Users\Youse\AppData\Local\Programs\Python\Python312...
    builtin_module_names = ('_abc', '_ast', '_bisect', '_blake2', '_codecs...
    byteorder = 'little'
    copyright = 'Copyright (c) 2001-2023 Python Software Foundati...ematis...
    dllhandle = 140727031824384
    dont_write_bytecode = False
    exec_prefix = r'C:\Users\Youse\AppData\Local\Programs\Python\Python312...
    executable = r'C:\Users\Youse\AppData\Local\Programs\Python\Python312\...
    flags = sys.flags(debug=0, inspect=0, interactive=0, opt...ding=0, saf...
    float_info = sys.float_info(max=1.7976931348623157e+308, max_...epsilo...
    float_repr_style = 'short'
    hash_info = sys.hash_info(width=64, modulus=2305843009213693...iphash1...
    hexversion = 51119856
    implementation = namespace(name='cpython', cache_tag='cpython-312...as...
    int_info = sys.int_info(bits_per_digit=30, sizeof_digit=4, ..._str_dig...
    maxsize = 9223372036854775807
    maxunicode = 1114111
    meta_path = [<_distutils_hack.DistutilsMetaFinder object>, <class '_fr...
    modules = {'__future__': <module '__future__' from 'C:\\Users\\Youse\\...
    orig_argv = [r'C:\Users\Youse\AppData\Local\Programs\Python\Python312\...
    path = [r'f:\JoeyCodes\PyDocs', r'C:\Users\Youse\AppData\Local\Program...
    path_hooks = [<class 'zipimport.zipimporter'>, <function FileFinder.pa...
    path_importer_cache = {r'C:\Users\Youse\AppData\Local\Programs\Python\...
    platform = 'win32'
    platlibdir = 'DLLs'
    prefix = r'C:\Users\Youse\AppData\Local\Programs\Python\Python312'
    pycache_prefix = None
    stderr = <_io.TextIOWrapper name='<stderr>' mode='w' encoding='cp1252'...
    stdin = <_io.TextIOWrapper name='<stdin>' mode='r' encoding='utf-8'>
    stdlib_module_names = frozenset({'__future__', '_abc', '_aix_support',...
    stdout = <_io.TextIOWrapper name='<stdout>' mode='w' encoding='cp1252'...
    thread_info = sys.thread_info(name='nt', lock=None, version=None)
    version = '3.12.6 (tags/v3.12.6:a4a2d2b, Sep  6 2024, 20:11:23) [MSC v...
    version_info = sys.version_info(major=3, minor=12, micro=6, releaselev...
    warnoptions = []
    winver = '3.12'

FILE
    (built-in)

importlib.util
Python Library Documentation: module importlib.util in importlib

NAME
    importlib.util - Utility code for constructing importers, etc.

MODULE REFERENCE
    https://docs.python.org/3.12/library/importlib.util.html

    The following documentation is automatically generated from the Python
    source files.  It may be incomplete, incorrect or include features that
    are considered implementation detail and may vary between Python
    implementations.  When in doubt, consult the module reference at the
    location listed above.

CLASSES
    importlib._abc.Loader(builtins.object)
        LazyLoader

    class LazyLoader(importlib._abc.Loader)
     |  LazyLoader(loader)
     |
     |  A loader that creates a module which defers loading until attribute access.
     |
     |  Method resolution order:
     |      LazyLoader
     |      importlib._abc.Loader
     |      builtins.object
     |
     |  Methods defined here:
     |
     |  __init__(self, loader)
     |      Initialize self.  See help(type(self)) for accurate signature.
     |
     |  create_module(self, spec)
     |      Return a module to initialize and into which to load.
     |
     |      This method should raise ImportError if anything prevents it
     |      from creating a new module.  It may return None to indicate
     |      that the spec should create the new module.
     |
     |  exec_module(self, module)
     |      Make the module load lazily.
     |
     |  ----------------------------------------------------------------------
     |  Class methods defined here:
     |
     |  factory(loader)
     |      Construct a callable which returns the eager loader made lazy.
     |
     |  ----------------------------------------------------------------------
     |  Data and other attributes defined here:
     |
     |  __abstractmethods__ = frozenset()
     |
     |  ----------------------------------------------------------------------
     |  Methods inherited from importlib._abc.Loader:
     |
     |  load_module(self, fullname)
     |      Return the loaded module.
     |
     |      The module must be added to sys.modules and have import-related
     |      attributes set properly.  The fullname is a str.
     |
     |      ImportError is raised on failure.
     |
     |      This method is deprecated in favor of loader.exec_module(). If
     |      exec_module() exists then it is used to provide a backwards-compatible
     |      functionality for this method.
     |
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from importlib._abc.Loader:
     |
     |  __dict__
     |      dictionary for instance variables
     |
     |  __weakref__
     |      list of weak references to the object

FUNCTIONS
    find_spec(name, package=None)
        Return the spec for the specified module.

        First, sys.modules is checked to see if the module was already imported. If
        so, then sys.modules[name].__spec__ is returned. If that happens to be
        set to None, then ValueError is raised. If the module is not in
        sys.modules, then sys.meta_path is searched for a suitable spec with the
        value of 'path' given to the finders. None is returned if no spec could
        be found.

        If the name is for submodule (contains a dot), the parent module is
        automatically imported.

        The name and package arguments work the same as importlib.import_module().
        In other words, relative module names (with leading dots) work.

    resolve_name(name, package)
        Resolve a relative module name to an absolute one.

    source_hash(source_bytes)
        Return the hash of *source_bytes* as used in hash-based pyc files.

DATA
    MAGIC_NUMBER = b'\xcb\r\r\n'

FILE
    c:\users\youse\appdata\local\programs\python\python312\lib\importlib\util.py

importlib.warnings
Python Library Documentation: module warnings

NAME
    warnings - Python part of the warnings subsystem.

MODULE REFERENCE
    https://docs.python.org/3.12/library/warnings.html

    The following documentation is automatically generated from the Python
    source files.  It may be incomplete, incorrect or include features that
    are considered implementation detail and may vary between Python
    implementations.  When in doubt, consult the module reference at the
    location listed above.

CLASSES
    builtins.object
        catch_warnings

    class catch_warnings(builtins.object)
     |  catch_warnings(*, record=False, module=None, action=None, category=<class 'Warning'>, lineno=0, append=False)
     |
     |  A context manager that copies and restores the warnings filter upon
     |  exiting the context.
     |
     |  The 'record' argument specifies whether warnings should be captured by a
     |  custom implementation of warnings.showwarning() and be appended to a list
     |  returned by the context manager. Otherwise None is returned by the context
     |  manager. The objects appended to the list are arguments whose attributes
     |  mirror the arguments to showwarning().
     |
     |  The 'module' argument is to specify an alternative module to the module
     |  named 'warnings' and imported under that name. This argument is only useful
     |  when testing the warnings module itself.
     |
     |  If the 'action' argument is not None, the remaining arguments are passed
     |  to warnings.simplefilter() as if it were called immediately on entering the
     |  context.
     |
     |  Methods defined here:
     |
     |  __enter__(self)
     |
     |  __exit__(self, *exc_info)
     |
     |  __init__(self, *, record=False, module=None, action=None, category=<class 'Warning'>, lineno=0, append=False)
     |      Specify whether to record warnings and if an alternative module
     |      should be used other than sys.modules['warnings'].
     |
     |      For compatibility with Python 3.0, please consider all arguments to be
     |      keyword-only.
     |
     |  __repr__(self)
     |      Return repr(self).
     |
     |  ----------------------------------------------------------------------
     |  Data descriptors defined here:
     |
     |  __dict__
     |      dictionary for instance variables
     |
     |  __weakref__
     |      list of weak references to the object

FUNCTIONS
    filterwarnings(action, message='', category=<class 'Warning'>, module='', lineno=0, append=False)
        Insert an entry into the list of warnings filters (at the front).

        'action' -- one of "error", "ignore", "always", "default", "module",
                    or "once"
        'message' -- a regex that the warning message must match
        'category' -- a class that the warning must be a subclass of
        'module' -- a regex that the module name must match
        'lineno' -- an integer line number, 0 matches all warnings
        'append' -- if true, append to the list of filters

    formatwarning(message, category, filename, lineno, line=None)
        Function to format a warning the standard way.

    resetwarnings()
        Clear the list of warning filters, so that no filters are active.

    showwarning(message, category, filename, lineno, file=None, line=None)
        Hook to write a warning to a file; replace if you like.

    simplefilter(action, category=<class 'Warning'>, lineno=0, append=False)
        Insert a simple entry into the list of warnings filters (at the front).

        A simple filter matches all modules and messages.
        'action' -- one of "error", "ignore", "always", "default", "module",
                    or "once"
        'category' -- a class that the warning must be a subclass of
        'lineno' -- an integer line number, 0 matches all warnings
        'append' -- if true, append to the list of filters

    warn(...)
        Issue a warning, or maybe ignore it or raise an exception.

        message
          Text of the warning message.
        category
          The Warning category subclass. Defaults to UserWarning.
        stacklevel
          How far up the call stack to make this warning appear. A value of 2 for
          example attributes the warning to the caller of the code calling warn().
        source
          If supplied, the destroyed object which emitted a ResourceWarning
        skip_file_prefixes
          An optional tuple of module filename prefixes indicating frames to skip
          during stacklevel computations for stack frame attribution.

    warn_explicit(...)
        Issue a warning, or maybe ignore it or raise an exception.

DATA
    __all__ = ['warn', 'warn_explicit', 'showwarning', 'formatwarning', 'f...

FILE
    c:\users\youse\appdata\local\programs\python\python312\lib\warnings.py