You have 3 free guides left 😟
Unlock your guides
You have 3 free guides left 😟
Unlock your guides

7.5 Finding modules

2 min readjune 24, 2024

Python are the building blocks of code organization and reuse. They allow developers to extend Python's functionality beyond its built-in features. Understanding how to manage, , and utilize modules is crucial for efficient programming.

From the Standard Library to third-party on , Python offers a vast ecosystem of modules. Navigating these resources, exploring module contents, and mastering import techniques are essential skills for every Python programmer. This knowledge empowers developers to leverage existing code and focus on solving unique problems.

Python Module Management

Python Standard Library vs PyPI

Top images from around the web for Python Standard Library vs PyPI
Top images from around the web for Python Standard Library vs PyPI
  • provides built-in modules that come with Python installation offers a wide range of functionality for common programming tasks (
    [math](https://www.fiveableKeyTerm:Math)
    ,
    [random](https://www.fiveableKeyTerm:Random)
    ,
    os
    ,
    [datetime](https://www.fiveableKeyTerm:datetime)
    )
  • Python Package Index (PyPI) serves as a repository of third-party packages and modules allows developers to share and distribute their own packages extends the functionality of Python beyond the Standard Library (
    numpy
    ,
    pandas
    ,
    requests
    ,
    flask
    )
    • Packages on PyPI can be installed using package managers like
      [pip](https://www.fiveableKeyTerm:pip)
  • provides access to the official Python documentation allows exploration of the Standard Library reference to find built-in modules
    • Read module descriptions, usage examples, and API references to evaluate the suitability of a module for a specific task based on its documentation
  • enables searching for third-party packages using keywords or package names
    • Review package descriptions, documentation, and user ratings to assess the package's popularity, maintenance, and community support
    • Check package dependencies and compatibility with your Python version and evaluate the package's license and terms of use

Module exploration and import functions

  • Importing modules from the Standard Library
    1. Use the
      import
      statement to import a module:
      import module_name
    2. Access module functions or variables using dot notation:
      module_name.function_name()
    3. Alternatively, use
      from module_name import function_name
      to import specific functions
      • Example:
        import math
        , then use
        math.sqrt(16)
        to calculate the square root of 16
  • Importing modules from PyPI
    1. Install the package using
      pip
      in the command line:
      pip install package_name
    2. Import the installed package in your Python script:
      import package_name
    3. Use the package's functions and classes as per its documentation
      • Example:
        import numpy as np
        , then use
        np.array([1, 2, 3])
        to create a NumPy array
  • Exploring modules
    • [dir()](https://www.fiveableKeyTerm:dir())
      function lists all available functions and variables in a module
    • [help()](https://www.fiveableKeyTerm:help())
      function accesses the module's documentation:
      help(module_name)
      • Inspect a specific function's documentation:
        help(module_name.function_name)
      • Example:
        dir(math)
        lists all functions in the
        math
        module, and
        help(math.sqrt)
        views the documentation for the
        sqrt()
        function

Advanced Module Management

  • : Isolated Python environments for project-specific dependencies
  • : Tools like
    pip
    to manage package versions and dependencies
  • : Python's system for locating modules (including the
    PYTHONPATH
    environment variable)
  • [__init__.py](https://www.fiveableKeyTerm:__init__.py)
    : Special file that defines a directory as a Python package
  • : Pre-built package format for faster installation of Python libraries
© 2024 Fiveable Inc. All rights reserved.
AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.


© 2024 Fiveable Inc. All rights reserved.
AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.

© 2024 Fiveable Inc. All rights reserved.
AP® and SAT® are trademarks registered by the College Board, which is not affiliated with, and does not endorse this website.
Glossary
Glossary