DEV Community

Cover image for 5 Useful Python Libraries
Soham
Soham

Posted on

5 Useful Python Libraries

Repetitive tasks you do at work. You send emails, create Excel reportings, extract data from PDFs, and (if you’re a data scientist like me) do tons of data analysis.
Nobody wants to do that, but in the end, someone has to do it. Sometimes that person might be you, so what to do when that happens?
Automate it with Python!
In this article, I’ll show you 5 Python libraries that can help you automate some common everyday tasks. Also, you’ll find instructions on how to properly install them and resources to learn each of them.
Mito: Automate Data Analysis
Mito is a Python library that helps us do data analysis in seconds. Instead of writing Python code, Mito allows us to interact with a Pandas dataframe as if it was an Excel workbook and generate Pandas code for us automatically.
For those who are looking to automate their Excel reporting while generating Python code, Mito is also a good option. With Mito, you can create visualizations, transform data with a spreadsheet and automate analysis with a couple of clicks. Mito will generate Python code for each edit you make in the Mito spreadsheet.
Installation
To install Mito, you have to open a new terminal/command prompt and download the Mito installer.

python -m pip install mitoinstaller

Then, run the installer:
python -m mitoinstaller install

It’s recommended to install Mito in a new virtual environment. Also, keep in mind that you need Python 3.6 or above and JupyterLab for Mito to work properly. For more details, check the official documentation and their Github.

Openpxl: Automate Excel Reporting

Openpyxl is a Python library that can help us automate our Excel reporting. With openpyxl, we can read an Excel file, write Excel formulas, make charts, and format a worksheet using Python.
This is a great library for those who want to stick to Excel while automating their reports with Python. With openpyxl, you won’t have to move from Excel to Python, but do the hard work in Python and save the results in an Excel file. In this way, you can improve your Python skills, and your coworkers with no programming skills won’t have to read your code. It’s a win-win.
Installation
We can easily install openpyxl using pip.
$ pip install openpyxl
Again, it’s recommended to install a new virtual environment before the installation. For more information check the documentation.
Requests: Make Your Life Easier With an API

Automation sometimes involves working with an API. APIs can help you collect real-world data and also simplify the development process of an application.
To work with an API you need to send requests to a server and then read the responses. The message sent by a client to a server is known as an HTTP request.
With the Requests library, we can interact with an API by sending HTTP requests and accessing the response data. This library has useful features such as passing parameters in URLs, sending custom headers, form data, and more.
Installation
To install Requests, we only need to run the command below in our terminal.
$ python -m pip install requests
You can check more information about this library in its documentation.

Remember that working with the Requests library is almost the same regardless of the API you work with.
Camelot: Automate Table Extraction from PDFs

Camelot is a library that can help you extract tables from PDFs using Python. These tables can be exported into a Pandas dataframe and other formats such as CSV, JSON, Excel, HTML, Markdown, and SQLite.
This is the perfect library for those who want complete control over table extraction because it offers tweakable settings to get your desired output. This feature is extremely useful considering that PDF table extraction is fuzzy.
Installation
Before installing Camelot, we need to have Ghostscript and Tkinter installed. In case you don’t have any of them, check the documentation to follow instructions on how to install these dependencies.
After installing the dependencies, we can easily install Camelot with pip or conda.
# using pip
$ pip install "camelot-py[base]"

using conda

$ conda install -c conda-forge camelot-py

Smtplib: Email Automation

Smtplib is a built-in Python module used for sending emails using the Simple Mail Transfer Protocol (SMTP). For example, we can send emails through the Gmail SMTP server using smtplib (you need to change the default settings of your Gmail account though, so check the resources below).
Once everything is set up you only need to write a few lines of code to send plain text emails. As you familiarize yourself with this library, you can do more advanced stuff such as attaching images, PDFs, creating HTML messages, and more.
Also, you can add the email package to read, write, and send more complex MIME messages.
Note: You don’t need to install smtplib or email because they come with Python.

Top comments (0)