12 Python Libraries that everyone should know



Productive and useful list of python libraries 

There are some sneaky libraries of python that only few people knows about. These libraries are really impressive for improving your daily productivity.

1- Begins

pip install begins

As far as user-interfaces go, most Python programs start out a scommand-line applications, and many remain so. It makes sense to offer your users the very best experience you can. For such programs, options are specified with command-line arguments, and the Python standard library offers the argparse library to help with that. argparse is a robust, solid implementation for command-line processing, but it is somewhat verbose to use. 

For example, here we have an extremely simple script that will add two numbers passed on the command line:

import begin
@begin.start(auto_convert=True)
def main(a: 'First value' = 0.0, b: 'Second value' = 0.0):
""" Add two numbers """
print(a + b)

2- Colorama

pip install colorama

Many of your desktop Python programs will only ever be used on the command line, so it makes sense to do whatever you can to improve the experience of your users as much as possible. The use of color can dramatically improve your user interface, and colorama makes it very easy to add splashes of color into your command-line applications.


from colorama import init, Fore, Back, Style
init(autoreset=True)
messages = ['blah blah blah',(Fore.LIGHTYELLOW_EX + Style.BRIGHT
+ BACK.MAGENTA + 'Alert!!!'),'blah blah blah']
for m in messages:
print(m)

3- PyQtGraph

pip install pyqtgraph
python -m pyqtgraph.examples

The most popular chart-plotting library in Python is matplotlib, but you may not yet have heard of the wonderful alternative, pyqtgraph. Pyqtgraph is not a one-to-one replacement for matplotlib; rather, it
offers a different selection of features and in particular is excellent for real-time and interactive visualization.

 

4- Pywebview

Pywebview gives you a one-line command to create a GUI window that wraps a system native “web view” window. By combining this with a Python web app like Flask or Bottle, it becomes very easy to create a local application with a GUI, while also taking advantage of the latest GUI technologies that have been developed in the browser space. The benefit to using the system native browser widget is that you don’t have to distribute a potentially large application bundle to your users.

 

5- Psutil

Psutil provides complete access to system information. Here’s a simple example of a basic report for CPU load sampled over 5 seconds:

import psutil
cpu = psutil.cpu_percent(interval=5, percpu=True)
print(cpu)
 

6- Watchdog

Watchdog is a high-quality, cross-platform library for receiving notifications of changes in the file system. Such file-system notifications
is a fundamental requirement in many automation applications, and
Watchdog handles all the low-level and cross-platform details of
notifications for system events. And, the great thing about Watchdog
is that it doesn’t use polling

 

7- ptpython

ptpython is an alternative interpreter interface, offering a beautiful interactive Python experience. As such, ptpython is more like a tool than a library to include in your own projects, but what a tool! with basic interface

 

8- Arrows

Though opinions differ, there are those who have found the standard library’s datetime module confusing to use. The module documentation itself in the first few paragraphs explains why: it provides
both naive and aware objects to represent dates and times. The naive
ones are the source of confusion, because application developers
increasingly find themselves working on projects in which time‐
zones are critically important. The dramatic rise of cloud infrastructure and software-as-a-service applications have contributed to the
reality that your application will frequently run in a different time‐
zone (e.g., on a server) than where developers are located, and different again to where your users are located.

import arrow
t0 = arrow.now()
print(t0)
t1 = arrow.utcnow()
print(t1)
difference = (t0 - t1).total_seconds()
print('Total difference: %.2f seconds' % difference)

9- Parsedatetime

parsedatetime is a wonderful library with a dedicated focus: parsing text into dates and times. As you’d expect, it can be obtained with pip install parsedatetime. The official documentation is very API-like, which makes it harder than it should be to get a quick overview of what the library offers, but you can get a pretty good idea of what’s available by browsing the extensive test suite.


import parsedatetime as pdt
cal = pdt.Calendar()
examples = [
"2016-07-16",
"2016/07/16",
"2016-7-16",
"2016/7/16",
"07-16-2016",
"7-16-2016",
"7-16-16",
"7/16/16",
]
print('{:30s}{:>30s}'.format('Input', 'Result'))
print('=' * 60)
for e in examples:
dt, result = cal.parseDT(e)
print('{:<30s}{:>30}'.format('"' + e + '"', dt.ctime()))
 

10- Sched

There is increasing interest in the creation of bots and other monitoring and automation applications. For these applications, a common requirement is to perform actions at specified times or specified intervals. This functionality is provided by the sched module in the standard library. There are already similar tools provided by operating systems, such as cron on Linux and Windows Task Scheduler, but with Python’s own sched module you can ignore these platform differences, as well as incorporate scheduled tasks
into a program that might have many other functions.

 

import sched
import time
from datetime import datetime, timedelta
scheduler = sched.scheduler(timefunc=time.time)
def saytime():
print(time.ctime())
scheduler.enter(10, priority=0, action=saytime)
saytime()
try:
scheduler.run(blocking=True)
except KeyboardInterrupt:
print('Stopped.')
 

11- Flit

flit is a tool that dramatically simplifies the process of submitting a Python package to the Python Package Index (PyPI). The traditional process begins by creating a setup.py file; simply figuring out how
to do that requires a considerable amount of work even to understand what to do. In contrast, flit will create its config file interactively, and for typical simple packages you’ll be ready to upload to
PyPI almost immediately.

 

12- Cython

Cython is a magical tool! As with most magical devices, it is difficult to describe exactly what it is. Cython is a tool that converts Python source code into C source code; this new code is then compiled into
a native binary that is linked to the CPython runtime.

 

Finally, we have awesome-python. It’s not a library, but rather a huge, curated list of a high-quality Python libraries covering a large number of domains. If you have not seen this list before, make sure to reserve some time before browsing because once you begin, you’ll have a hard time tearing yourself away!

 

If you liked my blog make sure to like and follow. For any service and help I’m mostly active on Instagram coding_memz.

 

Telegram

Personal

Telegram Channel

Channel



Previous Post Next Post