These 15 top Python libraries, you must know!

Why do I like Python? For beginners, this is a simple and easy to learn programming language, another reason: a large number of third-party libraries out of the box, it is 230,000 user-supplied software packages that make Python truly powerful and popular.

In this article, I have selected the 15 most useful software packages and introduced their functions and features.

Many people learn python and don't know where to start.
Many people learn python and after mastering the basic grammar, they don't know where to find cases to get started.
Many people who have done case studies do not know how to learn more advanced knowledge.
For these three types of people, I will provide you with a good learning platform, free to receive video tutorials, e-books, and course source code! ??¤
QQ group: 232030553

1. Dash

Dash is a relatively new software package. It is an ideal choice for building data visualization apps in pure Python, so it is especially suitable for anyone dealing with data. Dash is a mixture of Flask, Plotly.js and React.js.

2. Pygame

Pygame is a Python decorator for the SDL multimedia library. SDL (Simple DirectMedia Layer) is a cross-platform development library designed to provide low-level interfaces to the following content:

  • Audio

  • keyboard

  • mouse

  • Joystick

  • Graphics hardware based on OpenGL and Direct3D

Pygame is highly portable and can run on almost all platforms and operating systems. Although it has a complete game engine, you can also use this library to play MP3 files directly from Python scripts.

3. Pillow

Pillow is dedicated to processing images, you can use the library to create thumbnails, convert between file formats, rotate, apply filters, display images and more. This is ideal if you need to perform batch operations on many images.

In order to quickly understand it, look at the following code example (load and render an image):

4. Colorama

Colorama allows you to use colors in the terminal, which is very suitable for Python scripts. The documentation is short and interesting and can be found on the Colorama PyPI page.

5. JmesPath

It is very easy to use JSON in Python, because the mapping of JSON on Python dictionaries is very good. In addition, Python comes with its own excellent json library for parsing and creating JSON. For me, this is one of its best features. If I need to use JSON, I can consider using Python.

JMESPath makes it easier for Python to process JSON. It allows you to explicitly specify how to extract elements from a JSON document. Here are some basic examples to give you an idea of ​​its functions:

6. Requests

Requests is built on the world's most downloaded Python library urllib3, which makes web requests very simple, powerful and versatile.

The following code example illustrates how easy it is to use requests.

Requests can complete all the advanced tasks you can think of, such as:

  • Certification

  • Use cookies

  • Perform POST, PUT, DELETE, etc.

  • Use a custom certificate

  • Use Session

  • Use proxy

7. Simplejson

What's wrong with the native json module in Python? No! In fact, Python's json is simplejson. Meaning, Python takes a version of simplejson and merges it into each release. But using simplejson has some advantages:

  • It is suitable for more Python versions.

  • It is updated more frequently than the version that comes with Python.

  • It has (optional) parts written in C, so it is very fast.

Because of these facts, you will often see the following in scripts that use JSON:

I will only use the default json, unless you specifically need:

  • speed

  • Things not in the standard library

Simplejson is much faster than json because it implements some key parts in C. Unless you are processing millions of JSON files, you won't be interested in this speed.

8. Emoji

The Emoji library is very interesting, but not everyone likes emoji packages. Emoji packages are very useful when analyzing perspective media data.

The following is a simple code example:

9. Chardet

You can use the chardet module to detect the character set of a file or data stream. For example, this is useful when analyzing large amounts of random text. However, when you don't know what the character set is, you can also use it when processing remotely downloaded data.

10. Python-dateutil

The python-dateutil module provides a powerful extension to the standard datetime module. My experience is, where does the regular Python date and time function end, and python-dateutil appears.

You can do many great things with this library. I restrict these examples to examples that I find particularly useful: fuzzy analysis of dates in log files, for example:

For more features, see the full documentation, for example:

  • Calculate the relative increment (next month, next year, next Monday, last week of the month, etc.) and the relative increment between two objects on a given date.

  • Use a superset of the iCalendar specification to calculate dates based on repetition rules.

  • Time zone (tzinfo) implementation of tzfile file (/etc/localtime, /usr/share/zoneinfo, etc.), TZ environment string (all known formats), iCalendar format file, given range (with the help of relative increment) , Local computer time zone, fixed offset time zone, UTC time zone and time zone based on Windows registry.

  • The latest internal world time zone information based on the Olsen database.

  • Use Western, Orthodox or Julian algorithm to calculate the Easter Sunday date of any year.

11. Progress bar: progress and tqdm

There is a bit of cheating here, because these are two packages, but it is unfair to ignore one of them.

You can create your own progress bar, which may be interesting, but using the progress or tqdm package is faster and less error-prone.

progress

With this package, you can easily create a progress bar:

tqdm

The functionality of tqdm is roughly the same, but it seems to be the latest. First, make some demonstrations in the form of gif animation:

12. IPython

I'm sure you know the interactive shell of Python, which is a good way to run Python. But do you also know the IPython shell? If you often use interactive shells, but you don't know IPython, you should check it out!

Some of the features provided by the enhanced IPython shell include:

  • Comprehensive object introspection.

  • Input history records, which persist across sessions.

  • Cache output during sessions with automatically generated references.

  • Tab completion. By default, it supports the completion of python variables and keywords, file names and function keywords.

  • "Magic" commands are used to control the environment and perform many tasks related to IPython or operating systems.

  • Session recording and reloading.

  • Integrated access to the pdb debugger and Python profiler.

  • A little-known feature of IPython: its architecture also allows parallel and distributed computing.

IPython is the core of Jupyter Notebook. It is an open source web application that allows you to create and share documents containing real-time code, equations, visualizations, and narrative text.

13. Homeassistant

I like home automation. This is a hobby for me, but I still apologize for it, because it now controls most of our houses. I use Home Assistant to tie all the systems in the house together. Although it is indeed a complete application, you can also install it as a Python PyPI package.

  • Most of our lamps are automated, as are the blinds.

  • I monitor our natural gas usage, electricity usage and production (solar panels).

  • I can track the location of most phones and start operations when I enter an area, such as turning on a garage light when I get home.

  • It can also control all our entertainment systems, such as Samsung TVs and Sonos speakers.

  • It can automatically discover most devices on the network, so it's very easy to get started.

I have been using Home Assistant every day for 3 years and it is still in beta, but it is the best platform among all the platforms I have tried. It can integrate and control various devices and protocols, and is free and open source.

If you are interested in automating your house, make sure you have a chance! If you want to know more, please visit their official website. If possible, install it on the Raspberry Pi. So far, this is the easiest and safest way to get started. I installed it on a more powerful server in a Docker container.

14. Flask

Flask is my starter library for creating fast web services or simple websites. This is a microframework, which means Flask aims to keep the core simple but extensible. There are more than 700 official and community extensions.

If you know that you will develop a large-scale web application, you may need to study a more complete framework. The most popular in this category is Django.

15. BeautifulSoup

If you extract some HTML from the website, you need to parse it to get the actual content you need. Beautiful Soup is a Python library for extracting data from HTML and XML files. It provides an easy way to navigate, search and modify the parse tree. It is very powerful and can handle all kinds of HTML even if it is damaged. Trust me, HTML is often broken, so this is a very powerful feature.

Some of its main functions:

  • Beautiful Soup will automatically convert incoming documents to Unicode and outgoing documents to UTF-8. You don't need to think about coding.

  • Beautiful Soup sits on top of popular Python parsers such as lxml and html5lib, allowing you to try different parsing strategies or increase flexibility.

  • BeautifulSoup will parse any content you provide and do the job of traversing the tree for you. You can tell it to "find all links" or "find the table heading in bold and give me the text."

Guess you like

Origin blog.csdn.net/Python_sn/article/details/112662653