We earn commission when you buy through affiliate links.

This does not influence our reviews or recommendations.Learn more.

Libraries and Modules make the life of a programmer smooth.

image-157

We need some libraries and modules to overcome those problems.

Luckily Python supports a plethora of modules and libraries.

Python hasbuilt-inmodules as well asthird-partylibraries and modules for development.

image-158

We will see both integrated and third-party modules, which are very beneficial for Python projects.

Lets explore the built-in modules first.

Python comes with plenty of built-in modules for different use cases.

image-159

We will study the modules one by one according to their usage.

Collections

Python has different types ofcollectionsto store the collection of data.

Thecollectionsmodule provides additional features to the built-in collections.

If you takedequedata collection from thecollectionsmodule, it more like a Python list.

But, we canpushandpopthe elements from both sides.

Its faster than thelist.it’s possible for you to use thedequebased on your needs.

Lets see some real coding withcollections.dequedata collection.

initiate the above code; see the results.

We have other data collections as well in thecollectionsmodule.

Some of them are:

Its a subclass of the dict class.

Go to the documentation of thecollectionsmodule to explore all the data collections and methods.

CSV

We can use theCSV(comma-separated values) files to store the tabular data.

The most commonly used format for importing and exporting data from spreadsheets and databases.

Python comes with a module called CSVto handle theCSVfiles.

Lets see one example of reading the data from aCSV file.

Create a file with the namesample.csvin your laptop and paste the following data.

We have methods to read and write in the CSV module.

We will see how to read the data from the CSV files using the CSV module.

launch the above code to see the results.

We will also have an object calledcsv.writer()to write the data into theCSVfile.

Play with the other methods on your own using thedir()andhelp()built-in methods.

We have another module calledJSON,which is used for handlingJSONfiles.

Its also a built-in module.

Random

Python has a module calledrandomthat allows generating the data randomly.

We can produce anything randomly using different ways of therandommodule.

You check the other methods of therandommodule usingdir()andhelp()methods.

Lets write a small and simple game using therandommodule.

We can call it aNumber Guessing Game.

What is the Number Guessing Game?

The program will generate a random number in the range of 1 100.

The user will guess the number until it matches the random number generated by the program.

Then, the source code will display the number of guesses.

See the below code for the above program.

Tkinter

Tkinter is a built-in module for the development of GUI (Graphical User Interface) applications.

It is convenient for beginners.

The best support is to follow the officialdocs.

To get started with theTkinter,go to thedocsand start creating beautifulGUIapplications.

It allowsHTTP/1.1requests to send.

We can also add headers, data, and other things using Python dictionaries.

As it is a third-party module, we have to install it.

launch the following command in the terminal or command-line to install therequestsmodule.

Its straightforward to work with therequestsmodule.

We can start working with therequestswithout any prior knowledge.

Lets see how to send a get request and what it returns.

The above code will print the status_code, URL, and request method (GET, POST).

You will get the source of theURLas well.

you’ve got the option to access it with therequest.contentbytes.

Go to thedocsof therequestsmodule and explore more.

BeautifulSoup4

BeautifulSouplibrary is used for web scraping.

Its a handy module to work with.

Even beginners can start working with it using thedocs.

See the sample code to scrap the customer reports details.

you could installBeautifulSoupby typing the following command in the terminal/command line.

And, a simple program for your first scraping.

trigger the above code to see the magic of web scraping.

There are moreweb scraping frameworksout there for you to try.

All these are developed inC. ## Numpy

Numpyis used for scientific computation.

It allows us to work with multidimensional arrays.

Arrays implementation is not there in Python.

Mainly the developers usenumpyin their machine learning projects.

Its easy to learn and open-source library.

Almost every machine learning engineer or data scientist uses this module for complex mathematical computations.

initiate the following command to install thenumpymodule.

Pandas

Pandasis a data analysis module.

We can filter the data most effectively using thepandaslibrary.

It offers different types of data structures that are handy to work with.

It also provides file handling with different file formats.

plant the module using the following command.

Matplotlib

Matplotlibis a 2D graph plotting library.

you’re able to visualize the data usingMatplotlib.

We can generate images of the figures in different formats.

Quick Note:-you’re able to installAnacondato get all the libraries and modules required for Data Science.

If you are serious about learning Python for data science and ML then check out this brilliantUdemy course.

TensorFlow

TensorFlowis an end-to-end machine learning Python library that Google developed.

With TensorFlow, you might run standard machine learning algorithms, create neural networks, and do numerical computations.

However, a deep understanding of vectors and algebra is needed to work with TensorFlow.

Deep Learning is a subsect of Machine Learning.

With Keras, engineers take advantage of the cross-platform capabilities and scalability feature of TensorFlow.

To start using Keras, install it using pip;

pip install keras

Why Keras?

Keras is a free, open-source deep learning Python library.

Scikitt-Learn

Scikitt-Learnis a Python machine-learning module that is built onSciPy.

The module offers efficient and simple tools engineers can use to analyze predictive data.

In the Classification feature, you’re able to use this module to identify an objects category.

This feature is useful in image recognition and spam detection.

Scikkit-Learn is open source and commercially usable with a BSD license.

# Web Frameworks

We can find many web frameworks inPython.

We will discuss two frameworks that are widely used by the developers.

The two frameworks areDjangoandFlask.

Django

Djangois an open-source web framework developed in Python.

It is convenient to create websites withDjango.

We can generate any kind of site using this framework.

You have to familiar with the Python for Django.

But dont worry if youre not.Learning Djangois easy.

Flask

Flask is a micro web framework developed in Python.

It is more pythonic than Django.

It has excellent documentationhere.

It uses theJinjatemplate engine.

It is very complex to create big websites Flask.

Choose the framework based on the complexity of your website.

Django is gaining popularity among developers.

Its the most used framework for web development in Python.

Conclusion

I hope you got to know about different modules, libraries, and frameworks for Python.

Everyone is once a beginner.

Whatever you want to start, first go to the documentation and start learning it.

If you cant understand the docs, then find crash courses on theseeducational websites.

You may also check our post on how to install pip on different OS.