How To Get The List Of Built-in Modules In Python With Examples

Python’s extensive standard library comes equipped with a wide array of built-in modules that provide ready-made functions and utilities for various tasks. While Python’s built-in modules are a treasure trove for developers, it’s crucial to know how to access and explore them effectively. In this guide, we’ll delve into the step-by-step process of obtaining the list of built-in modules in Python, along with practical examples to illustrate their usage.

1. Using the `help()` Function.

One of the easiest ways to retrieve the list of built-in modules in Python is by utilizing the `help()` function. By passing the `modules` argument to `help()`, you can display the comprehensive list of built-in modules available in your Python environment.

import sys

# Using the help() function
help('modules')

This simple snippet will provide you with an extensive list of built-in modules, empowering you to explore and leverage Python’s rich collection of pre-built tools.

2. Accessing the `sys` Module.

Another approach to accessing the list of built-in modules involves utilizing the `sys` module. The `sys` module provides access to some variables used or maintained by the Python interpreter and allows you to retrieve a list of built-in module names.

import sys

# Getting a list of all the built-in modules
built_in_modules = sys.builtin_module_names

# Printing the list of built-in modules
for module in built_in_modules:
    print(module)

By executing this code snippet, you’ll obtain a list of built-in module names, granting you valuable insights into the wide range of functionalities available within the Python standard library.

Output.

_abc
_ast
_bisect
_blake2
_codecs
_codecs_cn
_codecs_hk
_codecs_iso2022
_codecs_jp
_codecs_kr
_codecs_tw
_collections
_contextvars
_csv
_datetime
_functools
_heapq
_imp
_io
_json
_lsprof
_md5
_multibytecodec
_opcode
_operator
_peg_parser
_pickle
_random
_sha1
_sha256
_sha3
_sha512
_signal
_sre
_stat
_statistics
_string
_struct
_symtable
_thread
_tracemalloc
_warnings
_weakref
_winapi
_xxsubinterpreters
array
atexit
audioop
binascii
builtins
cmath
errno
faulthandler
gc
itertools
marshal
math
mmap
msvcrt
nt
parser
sys
time
winreg
xxsubtype
zlib

3. Use The pkgutil Module to List All The Python Builtin Modules.

The `sys.builtin_module_names` method does not include all the built-in modules, particularly those implemented in C. To get a more comprehensive list, you can use the `pkgutil` module. Here’s an example of how to do it:

import pkgutil

# List all the built-in modules
built_in_modules = [name for _, name, _ in pkgutil.iter_modules()]

# Print the list of built-in modules
print(built_in_modules)

Output.

['_asyncio', '_bz2', '_ctypes', '_ctypes_test', '_decimal', '_elementtree', '_hashlib', '_lzma', '_msi', '_multiprocessing', '_overlapped', '_queue', '_socket', '_sqlite3', '_ssl', '_testbuffer', '_testcapi', '_testconsole', '_testimportmultiple', '_testinternalcapi', '_testmultiphase', '_tkinter', '_uuid', '_zoneinfo', 'pyexpat', 'select', 'unicodedata', 'winsound', '__future__', 
'_aix_support', '_bootlocale', '_bootsubprocess', '_collections_abc', '_compat_pickle', '_compression', '_markupbase', '_nsis', 
'_osx_support', '_py_abc', '_pydecimal', '_pyio', '_sitebuiltins', '_strptime', '_system_path', '_threading_local', '_weakrefset', 'abc', 'aifc', 'antigravity', 'argparse', 'ast', 'asynchat', 'asyncio', 'asyncore', 'base64', 'bdb', 'binhex', 'bisect', 'bz2', 'cProfile', 'calendar', 'cgi', 'cgitb', 'chunk', 'cmd', 'code', 'codecs', 'codeop', 'collections', 'colorsys', 'compileall', 
'concurrent', 'configparser', 'contextlib', 'contextvars', 'copy', 'copyreg', 'crypt', 'csv', 'ctypes', 'curses', 'dataclasses', 'datetime', 'dbm', 'decimal', 'difflib', 'dis', 'distutils', 'doctest', 'email', 'encodings', 'ensurepip', 'enum', 'filecmp', 'fileinput', 'fnmatch', 'formatter', 'fractions', 'ftplib', 'functools', 'genericpath', 'getopt', 'getpass', 'gettext', 'glob', 'graphlib', 'gzip', 'hashlib', 'heapq', 'hmac', 'html', 'http', 'idlelib', 'imaplib', 'imghdr', 'imp', 'importlib', 'inspect', 'io', 'ipaddress', 'json', 'keyword', 'lib2to3', 'linecache', 'locale', 'logging', 'lzma', 'mailbox', 'mailcap', 'mimetypes', 'modulefinder', 'msilib', 'multiprocessing', 'netrc', 'nntplib', 'ntpath', 'nturl2path', 'numbers', 'opcode', 'operator', 'optparse', 'os', 'pathlib', 'pdb', 'pickle', 'pickletools', 'pipes', 'pkgutil', 'platform', 'plistlib', 'poplib', 'posixpath', 'pprint', 
'profile', 'pstats', 'pty', 'py_compile', 'pyclbr', 'pydoc', 'pydoc_data', 'queue', 'quopri', 'random', 're', 'reprlib', 'rlcompleter', 'runpy', 'sched', 'secrets', 'selectors', 'shelve', 'shlex', 'shutil', 'signal', 'site', 'smtpd', 'smtplib', 'sndhdr', 'socket', 'socketserver', 'sqlite3', 'sre_compile', 'sre_constants', 'sre_parse', 'ssl', 'stat', 'statistics', 'string', 'stringprep', 'struct', 'subprocess', 'sunau', 'symbol', 'symtable', 'sysconfig', 'tabnanny', 'tarfile', 'telnetlib', 'tempfile', 'test'', 'turtledemo', 'types', 'typing', 'unittest', 'urllib', 'uu', 'uuid', 'venv', 'warnings', 'wave', 'weakref', 'webbrowser', 'wsgiref', 'xdrlib', 'xml', 'xmlrpc', 'zipapp', 'zipfile', 'zipimport', 'zoneinfo', 'cwp', 'OpenAIAuth', 'aiohttp', 'aiosignal', 'anyio', 'async_timeout', 'attr', 'attrs', 'cachetools', 'charset_normalizer', 'chatgpt', 'cmd_2to3', 'colorama', 'deprecated', 'frozenlist', 'future', 'h11', 'httpcore', 'httpx', 'idna', 'libfuturize', 'libpasteurize', 'markdown_it', 'mdurl', 'multidict', 'openai', 'packaging', 'past', 'pip', 'pyarmor', 'pygments', 'pyparsing', 'redis', 'requests', 'revChatGPT', 'rfc3986', 'rich', 'sniffio', 'tls_client', 'tqdm', 'urllib3', 'whois', 'wrapt', 'yarl', 'Cython', 'IPython', 'OpenSSL', 'PIL', 'PyQt5', 'TBB', '_argon2_cffi_bindings', '_black_version', '_cffi_backend', '_distutils_hack', '_plotly_future_', '_plotly_utils', '_pyrsistent_version', '_pytest', '_yaml', 'adodbapi', 'alabaster', 'anaconda_navigator', 'anaconda_project', 'appdirs', 'argon2', 'arrow', 'astroid', 'astropy', 'asttokens', 'atomicwrites', 'automat', 'autopep8', 'babel', 'backcall', 'backports', 'bcrypt', 'binaryornot', 
'binstar_client', 'bitarray', 'bkcharts', 'black', 'blackd', 'bleach', 'blib2to3', 'bokeh', 'boto3', 'botocore', 'bottleneck', 'brotli', 'bs4', 'certifi', 'cffi', 'chardet', 'click', 'cloudpickle', 'clyent', 'colorcet', 'comtypes', 'conda', 'conda_build', 
'conda_content_trust', 'conda_env', 'conda_pack', 'conda_package_handling', 'conda_token', 'conda_verify', 'constantly', 'cookiecutter', 'cryptography', 'cssselect', 'curl', 'cycler', 'cython', 'cytoolz', 'daal4py', 'dask', 'datashader', 'datashape', 'dateutil', 'debugpy', 'decorator', 'defusedxml', 'diff_match_patch', 'distributed', 'docutils', 'entrypoints', 'erfa', 'et_xmlfile', 'executing', 'fastjsonschema', 'filelock', 'flake8', 'flask', 'fontTools', 'fsspec', 'gensim', 'glob2', 'google_crc32c', 'greenlet', 'grpc', 'h5py', 'hamcrest', 'heapdict', 'holoviews', 'hvplot', 'hyperlink', 'imagecodecs', 'imageio', 'imagesize', 'importlib_metadata', 'incremental', 'inflection', 'iniconfig', 'intake', 'intervaltree', 'ipykernel', 'ipykernel_launcher', 'ipython_genutils', 'ipywidgets', 'isapi', 'isort', 'isympy', 'itemadapter', 'itemloaders', 'itsdangerous', 'jdcal', 'jedi', 'jinja2', 'jinja2_time', 'jmespath', 'joblib', 'json5', 'jsonschema', 'jupyter', 'jupyter_client', 'jupyter_console', 'jupyter_core', 'jupyter_server', 'jupyterlab', 'jupyterlab_plotly', 'jupyterlab_pygments', 'jupyterlab_server', 'jupyterlab_widgets', 'jwt', 'keyring', 'kiwisolver', 'lazy_object_proxy', 'libarchive', 'lief', 'llvmlite', 'locket', 'lxml', 'markdown', 'markupsafe', 'matplotlib', 'matplotlib_inline', 'mccabe', 'menuinst', 'mistune', 'mkl', 'mkl_fft', 'mkl_random', 'mock', 'mpmath', 'msgpack', 'multipledispatch', 'munkres', 'mypy_extensions', 'nacl', 'navigator_updater', 'nbclassic', 'nbclient', 'nbconvert', 'nbformat', 'nest_asyncio', 'networkx', 'nltk', 'nose', 'notebook', 'numba', 'numbergen', 'numexpr', 'numpy', 'numpydoc', 'olefile', 'onedal', 'openpyxl', 'pandas', 'pandocfilters', 'panel', 'param', 'paramiko', 'parsel', 'parso', 'partd', 'pathspec', 'patsy', 'pep8', 'pexpect', 'pickleshare', 'pkg_resources', 'pkginfo', 'plotly', 'pluggy', 'poyo', 'prometheus_client', 'prompt_toolkit', 'protego', 'psutil', 'ptyprocess', 'pure_eval', 'pvectorc', 'py', 'pyasn1', 'pyasn1_modules', 'pycodestyle', 'pycosat', 'pycparser', 'pyct', 'pycurl', 'pydispatch', 'pydocstyle', 'pyflakes', 'pylab', 'pylint', 'pyls_spyder', 'pylsp', 'pylsp_black', 'pylsp_jsonrpc', 'pyodbc', 'pyreadline', 'pyrsistent', 'pytest', 'pythoncom', 'pytz', 'pyviz_comms', 'pywt', 'pyximport', 'qdarkstyle', 'qstylizer', 'qtawesome', 'qtconsole', 'qtpy', 'queuelib', 'readline', 'regex', 'repo_cli', 'requests_file', 'rope', 'rsa', 'rtree', 'ruamel_yaml', 'run', 's3transfer', 'scipy', 'scrapy', 'seaborn', 'send2trash', 'service_identity', 'setuptools', 'sip', 'sipconfig', 'sipdistutils', 'six', 'skimage', 'sklearn', 'sklearnex', 'slugify', 'smart_open', 'snappy', 'snowballstemmer', 'socks', 'sockshandler', 'sortedcollections', 'sortedcontainers', 'soupsieve', 'sphinx', 'spyder', 'spyder_kernels', 'sqlalchemy', 'stack_data', 'statsmodels', 'sympy', 'tables', 'tabulate', 'tbb', 'tblib', 'tenacity', 'terminado', 'test_pycosat', 'testpath', 'text_unidecode', 'textdistance', 'threadpoolctl', 'three_merge', 'tifffile', 'tinycss', 'tldextract', 'tlz', 'toml', 'tomli', 'toolz', 'tornado', 'traitlets', 'twisted', 'typed_ast', 'typing_extensions', 'ujson', 'unidecode', 'w3lib', 'watchdog', 'wcwidth', 'webencodings', 'websocket', 'werkzeug', 'wheel', 'widgetsnbextension', 'win32com', 'win32ctypes', 'win_inet_pton', 'win_unicode_console', 'wincertstore', 'winpty', 'xarray', 'xlrd', 'xlsxwriter', 'xlwings', 'yaml', 'yapf', 'yapftests', 'zict', 'zipp', 'zmq', 'zope', 'vboxapi', '_win32sysloader', '_winxptheme', 'mmapfile', 'odbc', 'perfmon', 'servicemanager', 'timer', 'win32api', 'win32clipboard', 'win32console', 'win32cred', 'win32crypt', 'win32event', 'win32evtlog', 'win32file', 'win32gui', 'win32help', 'win32inet', 'win32job', 'win32lz', 'win32net', 'win32pdh', 'win32pipe', 'win32print', 'win32process', 'win32profile', 'win32ras', 'win32security', 'win32service', 'win32trace', 'win32transaction', 'win32ts', 'win32wnet', 'winxpgui', 'afxres', 'commctrl', 'dbi', 'mmsystem', 'netbios', 'ntsecuritycon', 'pywin32_bootstrap', 'pywin32_testutil', 'pywintypes', 'rasutil', 'regcheck', 'regutil', 'sspi', 'sspicon', 'win2kras', 'win32con', 'win32cryptcon', 'win32evtlogutil', 'win32gui_struct', 'win32inetcon', 'win32netcon', 'win32pdhquery', 'win32pdhutil', 'win32rcparser', 'win32serviceutil', 'win32timezone', 'win32traceutil', 'win32verstamp', 'winerror', 
'winioctlcon', 'winnt', 'winperf', 'winxptheme', 'dde', 'pywin', 'win32ui', 'win32uiole']

This method will give you a more exhaustive list, which includes the `os` module and other built-in modules that might not be listed using `sys.builtin_module_names`.

4. Conclusion.

In conclusion, Python’s built-in modules offer a plethora of resources that can significantly streamline the development process. By mastering the techniques for accessing and exploring built-in modules, you can unlock the full potential of Python’s standard library, thereby enhancing the efficiency and robustness of your code.

By incorporating the methods outlined in this guide, you can seamlessly access the list of built-in modules and harness their power to create sophisticated and feature-rich Python applications.

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.