Usage¶
Getting The List of Libraries¶
stdlib_list.stdlib_list returns the list of libraries in stdlib for any given version (by default, current python version).
In particular:
In [1]: from stdlib_list import stdlib_list
In [2]: libs = stdlib_list("3.4")
In [3]: libs[:6]
Out[3]: ['__future__', '__main__', '_dummy_thread', '_thread', 'abc', 'aifc']
Checking if a Module is part of stdlib¶
stdlib_list.in_stdlib provides an efficient way to check if a module name is part of stdlib.
It relies on @lru_cache to cache the stdlib list and query results for similar calls. Therefore it is much more efficient than module_name in stdlib_list() especially if you wish to perform multiple checks.
In particular:
>>> from stdlib_list import in_stdlib
>>> in_stdlib('zipimport') # built in
True
>>> in_stdlib('math') # C-API stdlib module, but linked as extension (on my machine)
True
>>> in_stdlib('numpy') # C-API extension, not stdlib
False
>>> in_stdlib('sys') # built-in (and special)
True
>>> in_stdlib('os') # Python code in stdlib
True
>>> in_stdlib('requests') # Python code, not stdlib
False
- stdlib_list.in_stdlib(module_name, version=None)[source]¶
Return a
boolindicating if modulemodule_nameis in the list of stdlib symbols for python versionversion. IfversionisNone(default), the version of current python interpreter is used.Note that
Truewill be returned for built-in modules too, since this project considers they are part of stdlib. See :issue:21.It relies on
@lru_cacheto cache the stdlib list and query results for similar calls. Therefore it is much more efficient thanmodule_name in stdlib_list()especially if you wish to perform multiple checks.- Parameters:
module_name (str|None) – The module name (as a string) to query for.
version (str|None) – The version (as a string) whose list of libraries you want
(one of
"2.6","2.7","3.2","3.3","3.4", or"3.5"). If not specified, the current version of Python will be used.- Returns:
A bool indicating if the given module name is part of standard libraries
for the specified version of Python. :rtype: list
- stdlib_list.stdlib_list(version=None)[source]¶
Given a
version, return alistof names of the Python Standard Libraries for that version. These names are obtained from the Sphinx inventory file (used insphinx.ext.intersphinx).- Parameters:
version (str|None) – The version (as a string) whose list of libraries you want
(one of
"2.6","2.7","3.2","3.3","3.4", or"3.5"). If not specified, the current version of Python will be used.- Returns:
A list of standard libraries from the specified version of Python
- Return type:
list