[ ![Python logo](../_static/py.svg) ](https://www.python.org/)

Theme  Auto  Light  Dark

###  [ Table of Contents ](../contents.html)

  * 5\. The import system 
    * 5.1. ` importlib  `
    * 5.2. Packages 
      * 5.2.1. Regular packages 
      * 5.2.2. Namespace packages 
    * 5.3. Searching 
      * 5.3.1. The module cache 
      * 5.3.2. Finders and loaders 
      * 5.3.3. Import hooks 
      * 5.3.4. The meta path 
    * 5.4. Loading 
      * 5.4.1. Loaders 
      * 5.4.2. Submodules 
      * 5.4.3. Module spec 
      * 5.4.4. Import-related module attributes 
      * 5.4.5. module.__path__ 
      * 5.4.6. Module reprs 
      * 5.4.7. Cached bytecode invalidation 
    * 5.5. The Path Based Finder 
      * 5.5.1. Path entry finders 
      * 5.5.2. Path entry finder protocol 
    * 5.6. Replacing the standard import system 
    * 5.7. Package Relative Imports 
    * 5.8. Special considerations for __main__ 
      * 5.8.1. __main__.__spec__ 
    * 5.9. References 

####  Previous topic

[ 4\.  Execution model ](executionmodel.html "previous chapter")

####  Next topic

[ 6\.  Expressions ](expressions.html "next chapter")

###  This Page

  * [ Report a Bug ](../bugs.html)
  * [ Show Source ](https://github.com/python/cpython/blob/main/Doc/reference/import.rst)

###  Navigation

  * [ index ](../genindex.html "General Index")
  * [ modules ](../py-modindex.html "Python Module Index") | 
  * [ next ](expressions.html "6. Expressions") | 
  * [ previous ](executionmodel.html "4. Execution model") | 
  * ![Python logo](../_static/py.svg)
  * [ Python ](https://www.python.org/) » 
  *   *   * [ 3.12.3 Documentation ](../index.html) » 
  * [ The Python Language Reference ](index.html) » 
  * [ 5\.  The import system ]()
  * | 
  * Theme  Auto  Light  Dark  | 

#  5\.  The import system  Â¶

Python code in one [ module  ](../glossary.html#term-module) gains access to
the code in another module by the process of [ importing
](../glossary.html#term-importing) it. The [ ` import  `
](simple_stmts.html#import) statement is the most common way of invoking the
import machinery, but it is not the only way. Functions such as [ `
importlib.import_module()  `
](../library/importlib.html#importlib.import_module "importlib.import_module")
and built-in [ ` __import__()  ` ](../library/functions.html#import__
"__import__") can also be used to invoke the import machinery.

The [ ` import  ` ](simple_stmts.html#import) statement combines two
operations; it searches for the named module, then it binds the results of
that search to a name in the local scope. The search operation of the ` import
` statement is defined as a call to the [ ` __import__()  `
](../library/functions.html#import__ "__import__") function, with the
appropriate arguments. The return value of [ ` __import__()  `
](../library/functions.html#import__ "__import__") is used to perform the name
binding operation of the ` import  ` statement. See the ` import  ` statement
for the exact details of that name binding operation.

A direct call to [ ` __import__()  ` ](../library/functions.html#import__
"__import__") performs only the module search and, if found, the module
creation operation. While certain side-effects may occur, such as the
importing of parent packages, and the updating of various caches (including [
` sys.modules  ` ](../library/sys.html#sys.modules "sys.modules") ), only the
[ ` import  ` ](simple_stmts.html#import) statement performs a name binding
operation.

When an [ ` import  ` ](simple_stmts.html#import) statement is executed, the
standard builtin [ ` __import__()  ` ](../library/functions.html#import__
"__import__") function is called. Other mechanisms for invoking the import
system (such as [ ` importlib.import_module()  `
](../library/importlib.html#importlib.import_module "importlib.import_module")
) may choose to bypass [ ` __import__()  `
](../library/functions.html#import__ "__import__") and use their own solutions
to implement import semantics.

Whe