This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: Command to display all available Import Library
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.5
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: arupchakrav, benjamin.peterson, martin.panter, pitrou, rhettinger
Priority: low Keywords:

Created on 2014-02-04 01:23 by arupchakrav, last changed 2022-04-11 14:57 by admin.

Messages (8)
msg210171 - (view) Author: Arup Chakravarty (arupchakrav) Date: 2014-02-04 01:23
Have a built-in mechanism to display all available import libraries within the interpreter. Like what is available through the built-in dir function.
msg210172 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2014-02-04 01:33
>>> import sys
>>> sys.modules.keys()
['google', 'copy_reg', 'sre_compile', '_sre', 'encodings', 'site', '__builtin__', 'sysconfig', '__main__', 'encodings.encodings', 'abc', 'posixpath', '_weakrefset', 'errno', 'encodings.codecs', 'sre_constants', 're', '_abcoll', 'types', '_codecs', 'encodings.__builtin__', '_warnings', 'genericpath', 'stat', 'zipimport', '_sysconfigdata', 'warnings', 'UserDict', 'encodings.utf_8', 'sys', 'codecs', 'readline', 'os.path', 'signal', 'traceback', 'linecache', 'posix', 'encodings.aliases', 'exceptions', 'sre_parse', 'os', '_weakref']
msg210173 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2014-02-04 03:04
This is not what the OP asked, AFAICT. sys.modules is just the set of currently imported modules, not all potentially importable modules.
msg210174 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2014-02-04 03:26
I guess I have no idea what the OP is asking for then. dir() certainly only gives immediately available builtins.
msg210178 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2014-02-04 06:06
+1 for the OP's original idea (something like a dir_modules() function that lists out all possible imports).

I think something like this must already be present in some of the Python front-ends such as ipython and bpython.  That is how they support tab-completion for imports:

In [1]: import co
code         codeop       colorsys     compileall   contextlib   copy
codecs       collections  commands     compiler     cookielib    copy_reg

In [1]: import re
re        readline  repr      requests  resource  reverend  rexec
msg210238 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2014-02-04 15:00
The trick would be how to query finders to say "what could you find?" There is no API for that so either something pragmatic that won't work in the face of e.g. zipfiles would need to be used or a new optional API on finders to list what the tail name of modules it can find are (but without the package name as most finders just use fullname.rpartition('.')[-1] to figure out what they are looking for).
msg226682 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2014-09-10 05:41
I wrote some code that does something like this for a hacky custom readline completer. See the import_list() method at <>. It looks like I’m using a combination of “sys.builtin_module_names” and pkgutil.iter_modules(), with a whole lot of compatibility and bug workarounds.
msg364554 - (view) Author: Brett Cannon (brett.cannon) * (Python committer) Date: 2020-03-18 18:39
When a replacement for pkgutil.walk_packages() is added to importlib to work appropriately with the import system then this should be doable. See for work to replace pkgutil as appropriate.
Date User Action Args
2022-04-11 14:57:58adminsetgithub: 64705
2020-03-18 18:39:54brett.cannonsetnosy: - brett.cannon
2020-03-18 18:39:49brett.cannonsetmessages: + msg364554
2014-09-10 05:41:44martin.pantersetnosy: + martin.panter
messages: + msg226682
2014-02-04 15:00:54brett.cannonsetmessages: + msg210238
2014-02-04 06:06:36rhettingersetstatus: closed -> open
priority: normal -> low

versions: + Python 3.5, - Python 2.7
nosy: + brett.cannon, rhettinger

messages: + msg210178
resolution: rejected ->
2014-02-04 03:26:46benjamin.petersonsetmessages: + msg210174
2014-02-04 03:04:56pitrousetnosy: + pitrou
messages: + msg210173
2014-02-04 01:33:20benjamin.petersonsetstatus: open -> closed

nosy: + benjamin.peterson
messages: + msg210172

resolution: rejected
2014-02-04 01:23:14arupchakravcreate