##  5.9.  References  Â¶

The import machinery has evolved considerably since Pythonâs early days. The
original [ specification for packages
](https://www.python.org/doc/essays/packages/) is still available to read,
although some details have changed since the writing of that document.

The original specification for [ ` sys.meta_path  `
](../library/sys.html#sys.meta_path "sys.meta_path") was  [ **PEP 302**
](https://peps.python.org/pep-0302/) , with subsequent extension in  [ **PEP
420** ](https://peps.python.org/pep-0420/) .

[ **PEP 420** ](https://peps.python.org/pep-0420/) introduced [ namespace
packages  ](../glossary.html#term-namespace-package) for Python 3.3.  [ **PEP
420** ](https://peps.python.org/pep-0420/) also introduced the ` find_loader()
` protocol as an alternative to ` find_module()  ` .

[ **PEP 366** ](https://peps.python.org/pep-0366/) describes the addition of
the ` __package__  ` attribute for explicit relative imports in main modules.

[ **PEP 328** ](https://peps.python.org/pep-0328/) introduced absolute and
explicit relative imports and initially proposed ` __name__  ` for semantics
[ **PEP 366** ](https://peps.python.org/pep-0366/) would eventually specify
for ` __package__  ` .

[ **PEP 338** ](https://peps.python.org/pep-0338/) defines executing modules
as scripts.

[ **PEP 451** ](https://peps.python.org/pep-0451/) adds the encapsulation of
per-module import state in spec objects. It also off-loads most of the
boilerplate responsibilities of loaders back onto the import machinery. These
changes allow the deprecation of several APIs in the import system and also
addition of new methods to finders and loaders.

Footnotes

[  1  ]

See [ ` types.ModuleType  ` ](../library/types.html#types.ModuleType
"types.ModuleType") .

[  2  ]

The importlib implementation avoids using the return value directly. Instead,
it gets the module object by looking the module name up in [ ` sys.modules  `
](../library/sys.html#sys.modules "sys.modules") . The indirect effect of this
is that an imported module may replace itself in [ ` sys.modules  `
](../library/sys.html#sys.modules "sys.modules") . This is implementation-
specific behavior that is not guaranteed to work in other Python
implementations.

###  [ 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  | 

© [ Copyright ](../copyright.html) 2001-2