[issue42955] Add sys.module_names: list of stdlib module names (Python and extension modules)

STINNER Victor report at bugs.python.org
Mon Jan 18 08:54:44 EST 2021


STINNER Victor <vstinner at python.org> added the comment:

Use cases for sys.module_names:

* When computing dependencies of a project, ignore modules which are part of the stdlib: https://github.com/jackmaney/pypt/issues/3

* Trace the execution of third party code, but ignore stdlib, use --ignore-module option of trace: https://stackoverflow.com/questions/6463918/how-can-i-get-a-list-of-all-the-python-standard-library-modules

* When reformatting a Python source file, group imports of stdlib modules. The isort module contains the list of stdlib modules, one list py Python version: https://github.com/PyCQA/isort/tree/develop/isort/stdlibs which is generated from the online Python documentation.

---

The isort uses the following script to generate the list of stdlib modules:
https://github.com/PyCQA/isort/blob/develop/scripts/mkstdlibs.py

The script uses sphinx.ext.intersphinx.fetch_inventory(...)["py:module"]. This API uses objects.inv from the online Python documentation. Example of Python 3.9:

   https://docs.python.org/3.9/objects.inv

On the "dev" version, mkstdlibs.py lists 211 modules.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42955>
_______________________________________


More information about the Python-bugs-list mailing list