(Talk) Third Party Libraries
Last updated on 2026-05-22 | Edit this page
Libraries
A library is a collection of files (called modules) that contains code for use by other programs. In addition to functions, a library can contain classes, constants, and other elements so that you don’t have to write them yourself. Libraries simplify life for programmers, in that they provide reusable functions and classes which can be used to build applications.
The Python Standard Library
The Python Standard Library is a collection of modules that come pre-packaged with Python. These modules provide a wide range of functionality, including file I/O, networking, data processing, and more. Some of the most commonly used modules in the Python Standard Library include:
- os: Provides a way to interact with the operating system, such as reading and writing files, creating directories, and more.
- sys: Contains functions and variables that are used to manipulate the Python runtime environment.
- math: Provides mathematical functions and constants, such as trigonometric functions, logarithms, and more.
- datetime: Contains classes for working with dates and times.
- random: Provides functions for generating random numbers.
- re: Provides support for regular expressions.
- json: Provides functions for encoding and decoding JSON data.
You can find a complete list of modules in the Python Standard Library in the official Python documentation.
Third Party Libraries
Third-party libraries in Python are external packages that provide additional functionality beyond the standard library. These libraries are created and maintained by the community or other organizations, allowing developers to leverage pre-built code for various tasks, such as data analysis, web development, machine learning, and more. Some popular third-party libraries include:
- NumPy: For numerical computing.
- Pandas: For data manipulation and analysis.
- Matplotlib: A plotting library for creating static, animated, and interactive visualizations in Python.
- SciPy: For scientific and technical computing.
- pytorch: For deep learning and neural networks.
How to Import Third-Party Libraries
Unlike the Python Standard Library, third-party libraries are not
included with Python by default. In order to access their functionality,
you need to install them separately using a package manager like
pip or conda. Once installed, you can import
the library into your Python script using the import
statement.
Dependencies
A benefit / complication of third-party libraries is that they often
rely on other third-party libraries in order to function.
pandas, for example, relies on numpy. When you
install pandas, numpy will be installed as
well. pip and conda are package managers that
help manage these dependencies, automatically installing the required
version of a library and its dependencies.
Package Managers
pip: The Python Package Installer,
pip, is the default package manager for Python. It is used to install, upgrade, and manage Python packages. You can install a package usingpipby runningpip install package_namefrom the command line.conda: Conda is a package manager that is commonly used for data science and scientific computing. It can be used to install Python packages as well as other software packages. You can install a package using conda by running
conda install package_namefrom the command line.
Environment Management
When working with third-party libraries, it is often a good practice to create a virtual environment for your project to ensure that you are using the correct versions of the libraries and their dependencies.
This is less imporant when first starting up, but as you start to work on multiple projects, you may find that different projects require different versions of the same library. Virtual environments help to manage these dependencies and avoid conflicts between projects.
Some common tools for creating virtual environments include
venv1, conda2, and
poetry3.
Using Third-Party Libraries
To use a third-party library in your Python project, you typically need to follow these steps:
-
Install the Library: Before you can import a third-party library, you need to install it using a package manager like
piporconda. You can do this from the command line or terminal.Example:
-
Import the Library in Your Code: Once installed, you can import the library into your Python script using the
importstatement.Example:
-
Using Specific Functions or Classes: If you only need specific functions or classes from a library, you can import them directly.
Example:
Tips for Managing Third-Party Libraries
Virtual Environments: It’s often a good practice to create virtual environments (using
venvorvirtualenv) for your projects to manage dependencies separately and avoid conflicts between different projects.Requirements File: You can create a
requirements.txtfile listing all your project’s-
dependencies. This allows others (or yourself) to install all required packages easily using: