Home >Backend Development >Python Tutorial >Introducing 15 python libraries that are so useful that they make you cry

Introducing 15 python libraries that are so useful that they make you cry

coldplay.xixi
coldplay.xixiforward
2021-01-04 09:44:444710browse

Python video tutorialThe column introduces 15 useful python libraries

Introducing 15 python libraries that are so useful that they make you cry

Recommended (free): Python video tutorial

Why do I like Python? It's an easy-to-learn programming language for beginners, for another reason: the large number of third-party libraries available out of the box, and 230,000 user-contributed packages that make Python truly powerful and popular.

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

1. Dash

Dash is a relatively new package that is ideal for building data visualization apps in pure Python, making it especially suitable for anyone working with data. . Dash is a hybrid of Flask, Plotly.js and React.js.

Introducing 15 python libraries that are so useful that they make you cry

2. Pygame

Pygame is the Python decorator of the SDL multimedia library. SDL (Simple DirectMedia Layer) is a cross-platform Development library designed to provide a low-level interface to:

  • Audio

  • Keyboard

  • Mouse

  • Joystick

  • OpenGL and Direct3D based graphics hardware

Pygame has a high 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 specially designed for processing images, you can use this library to create thumbnails, convert between file formats, rotate, apply filters, Display images and so on. This is ideal if you need to perform batch operations on many images.

To understand it quickly, take a look at the following code example (which loads and renders the image):

Introducing 15 python libraries that are so useful that they make you cry

4. Colorama

Colorama allows you to work with colors in the terminal, perfect for Python scripts, the documentation is short and sweet and can be found on the Colorama PyPI page.

Introducing 15 python libraries that are so useful that they make you cry

5. JmesPath

Working with JSON in Python is very easy because JSON maps very well on Python dictionaries. Additionally, Python comes with its own excellent json library for parsing and creating JSON. To me, this is one of its best features. If I need to work with JSON, I might consider using Python.

JMESPath makes processing JSON in Python easier by allowing you to explicitly specify how to extract elements from a JSON document. Here are some basic examples to give you an idea of ​​its capabilities:

Introducing 15 python libraries that are so useful that they make you cry

6. Requests

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

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

Introducing 15 python libraries that are so useful that they make you cry

Requests can do all the advanced stuff you can think of, such as:

  • Authentication

  • Use cookies

  • Perform POST, PUT, DELETE, etc.

  • Use custom certificate

  • Use SessionSession

  • Use Proxy

7. Simplejson

Local in Python What's wrong with the json module? No! Actually, Python's json is simplejson. Meaning, Python took a version of simplejson and incorporated it into every distribution. But using simplejson has some advantages:

  • It works on more Python versions.

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

  • It has the (optional) part written in C, so it's very fast.

Due to these facts, you will often see the following in scripts that use JSON:

Introducing 15 python libraries that are so useful that they make you cry

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

  • 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 kind of speed.

8. Emoji

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

Introducing 15 python libraries that are so useful that they make you cry

The following is a simple code example:

Introducing 15 python libraries that are so useful that they make you cry

9. Chardet

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

10. Python-dateutil

The python-dateutil module provides powerful extensions to the standard datetime module. My experience is that where regular Python datetime functionality ends, python-dateutil comes in.

You can do a lot of cool things with this library. I've limited these examples to ones I've found particularly useful: Fuzzy analysis of dates in log files, for example:

Introducing 15 python libraries that are so useful that they make you cry

See the full documentation for more features, for example:

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

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

  • Time zone (tzinfo) implementation of tzfile files (/etc/localtime, /usr/share/zoneinfo, etc.), TZ environment strings (all known formats), iCalendar format files, Given a range (with the help of relative increments), local machine time zone, fixed offset time zone, UTC time zone and Windows registry based time zone.

  • Internal latest world time zone information based on the Olson database.

  • Calculate the Easter Sunday date for any year using the Western, Orthodox or Julian algorithm.

11. Progress bar: progress and tqdm

A little cheating here, since these are two packages, but it is not possible to ignore one of them Fair.

You can create your own progress bar, which might be fun, but using the progress or tqdm packages is faster and less error-prone.

progress

With the help of this package you can easily create progress bars:

Introducing 15 python libraries that are so useful that they make you cry

Introducing 15 python libraries that are so useful that they make you cry

tqdm

tqdm does roughly the same thing but seems to be the latest. First some demonstrations in the form of animated gifs:

Introducing 15 python libraries that are so useful that they make you cry

12. IPython

Introducing 15 python libraries that are so useful that they make you cry

I’m sure You know Python's interactive shell, which is a great way to run Python. But do you also know the IPython shell? If you use interactive shells regularly 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 persists across sessions.

  • Cache output results during a session with automatically generated references.

  • Tab completion, by default supports completion of python variables and keywords, file names and function keywords.

  • "Magic" command used to control the environment and perform many IPython or operating system related tasks.

  • Session recording and reloading.

  • Integrated access to the pdb debugger and Python profiler.

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

IPython is at the heart of Jupyter Notebook, an open source web application that lets you create and share documents containing live code, equations, visualizations, and narrative text.

13. Homeassistant

Introducing 15 python libraries that are so useful that they make you cry

I love home automation. It was a bit of a hobby for me, but one I still feel deeply sorry for as it now controls a large portion of our house. I use Home Assistant to tie together all the systems in the house. Although it is indeed a complete application, you can also install it as a Python PyPI package.

  • Most of our light fixtures are automated, as are our blinds.

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

  • I can track the location of most phones and initiate actions when they enter an area, such as turning on the garage lights 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 is very easy to get started.

I've been using Home Assistant every day for 3 years, it's still in beta, but it's the best platform out of all the ones I've tried. It is able to integrate and control a variety of devices and protocols, and is all free and open source.

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

14. Flask

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

If you know you will be developing a large web application, you may want to look into a more complete framework. The most popular in this category is Django.

15. BeautifulSoup

If you extracted some HTML from your website, you need to parse it to get the actual content you want. Beautiful Soup is a Python library for extracting data from HTML and XML files. It provides simple methods to navigate, search and modify parse trees. It's very powerful and, even if broken, is capable of handling all kinds of HTML. Trust me, HTML is often broken, so this is a very powerful feature.

Some of its main features:

  • Beautiful Soup automatically converts 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 parses whatever you provide and does the work of walking the tree for you. You can tell it "Find all links," or "Find the table title with bold font and give me that text."

The above is the detailed content of Introducing 15 python libraries that are so useful that they make you cry. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete