Python Libraries

Learn via video course
FREE
View all courses
Python Course for Beginners With Certification: Mastering the Essentials
Python Course for Beginners With Certification: Mastering the Essentials
by Rahul Janghu
1000
4.90
Start Learning
Python Course for Beginners With Certification: Mastering the Essentials
Python Course for Beginners With Certification: Mastering the Essentials
by Rahul Janghu
1000
4.90
Start Learning
Topics Covered

Overview

Python libraries are a large collection of utility tools in the form of code modules that provide several functions with multiple uses ranging from input/output, data visualization, socket manipullation, pulling data from the internet, os operations, scientific calculations, data manipulation and management, etc. A large number of python libraries are written in the C programming language and they provide code encapsulation and polymorphism in the form of functions that can be used within a python script.

What are Python Libraries?

  • Python Libraries are collections of python modules that provide several utilities
  • Python Libraries are written in many programming languages

When we talk about libraries, the first thing that comes into our mind is large quiet halls with rows of books upon books. In the same vein, python libraries are also large collections of python modules that provide a wide range of functionalities including but not limited to input/output, basic operations, data visualization, network manipulation, etc.

What are python libraries

Python libraries are a collection of utility methods, classes, and modules that can be used in a python application directly. These libraries provide pre-written methods and classes for use within python applications. Their use may range from anything from Input/Output to data manipulation and visualization etc. Python libraries may be written in a number of programming languages including C, Python, as well as Java in case of Jpython, etc. Python libraries provide code bundles that can be used repeatedly within a python application.

Working of Python Libraries

  • Python libraries are a collection of related code modules.
  • Python libraries provide code reusability and ease of access to complex code.

Python libraries are simply bundles of code within modules which may comprise documentation, classes, methods, etc. As the complexity of code increases, it becomes redundant to keep rewriting the same complex code again and again. We instead split complex code into modules and store them within libraries for ease of access so that we may use a code anywhere and as many times as we want. Using libraries, we may use the same code in multiple programs without having to define the methods multiple times.

When we import a library into a program, on use of the library modules, the program linker automatically searches for the library and utilizes the functionalities of the module as required. If the library is not present within the python runtime, we may have to install the library to use it.

Python Standard Library

The Python Standard Library is an extensive library consisting of a large number of modules that offer a wide range of functionalities like I/O, socket programming, patternmatching using Regular expression, creating/deleting directories, etc. The python standard library is written in C programming language and it consists of a number of functionalities required in everyday programming including Input/Output. The Python standard library is included with the installation of Python and as such need not be installed separately.

Some Important Python Libraries

In the following section, we shall look into a few of the important python libraries that are frequently in use and provide essential utilities.

  1. Matplotlib The matplotlib library is used in data visualization in python and is an important tool in Data Science. Matplotlib is a comprehensive library for creating static, animated, and interactive visualizations in Python. It can be used by installing the matplotlib library and importing the neccessary methods using the import keyword. It consists of a number of functions like plot(), scatter() bar() stem() step() etc.

  2. Pandas The Pandas or Python Data Analysis Library is another important tool in Data Sciences and provides utilities that help in Data Analysis. pandas is a fast, powerful, flexible and easy to use open source data analysis and manipulation tool, built on top of the Python programming language. Pandas is built on top of NumPy. It also provides a huge number of functions and can be accessed by installing the pandas library.

  3. NumPy NumPy is used for scientific calculations and it provides utilities that help in executing large mathematical calculations and it supports big matrices and multidimensional data. NumPy offers comprehensive mathematical functions, random number generators, linear algebra routines, Fourier transforms, and more.NumPy supports a wide range of hardware and computing platforms, and plays well with distributed, GPU, and sparse array libraries. It can be used by installing the numpy library.

  4. NetworkX The networkx library is used for studying graphs and networks in python. NetworkX is a Python package for the creation, manipulation, and study of the structure, dynamics, and functions of complex networks. It provides Data structures for graphs, digraphs, and multigraphs, many standard graph algorithms, network structure and analysis measures and many more features. It can be used by installing the networkx library.

  5. TensorFlow Tensor flow is another important python library used in large calculations. It has a comprehensive, flexible ecosystem of tools, libraries and community resources that lets researchers push the state-of-the-art in ML and developers easily build and deploy ML powered applications.

  6. Requests The requests Python Library lets us send HTTP/1.1 requests, add headers, form data, multipart files, and parameters with simple Python dictionaries. It also lets us receive response data in the same way.

The total number of Python libraries is extremely vast and cannot be included in this article. One can choose from hundreds of python libraries according to his or her requirements when writing in Python. This makes the python language extremely versatile as well as extremely powerful.

Use of Libraries in Python Program

Libraries store a number of interrelated modules. Whenever the need arises for any functionality of a module, we may import the library containing the module into any python program and use it.

Python libraries can be imported into a python script using the import keyword.

For example, if we are to import the string library, we can use the following syntax:

We may also assign a variable to the library using as, as shown in the following example:

Importing Specific Modules from a Library Module

We may also import specific modules from a library using the from keyword. For example:

Conclusion

  • Python libraries are a collection of related Python modules that offer various functionalities.
  • Python libraries provide ease of access and code reuse.
  • The Python standard library is bundled with python distributions and provides a number of utilities like Input/Output, etc.
  • There is a vast number of python libraries for various uses, which can be used according to the need of the user. This makes python extremely powerful and versatile.

Read More: