Home > Backend Development > Python Tutorial > Ten useful Python utility libraries, I recommend you try them!

Ten useful Python utility libraries, I recommend you try them!

王林
Release: 2023-04-13 09:43:12
forward
2966 people have browsed it

Ten useful Python utility libraries, I recommend you try them!

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 the 230,000 user-contributed packages that make Python truly powerful and popular.

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

1. Dash

Dash is a Python library for building web-based applications without JavaScript.

Dash is also a user interface library for creating analytical web applications. Those who use Python for data analysis, data mining, visualization, modeling, instrument control, and reporting can use Dash right away.

Ten useful Python utility libraries, I recommend you try them!

Dash is built on Plotly.js, React, and Flask to combine modern UI elements like dropdowns, sliders, and graphs with your analytical Python code .

Project address:

​https://www.php.cn/link/502cc2c94be1a7c4ca7ef25b8b50bc04​

2. Pillow

Pillow is specifically designed for working with images, you can use this 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.

To understand it quickly, take a look at the following code example (loading and rendering images):

Ten useful Python utility libraries, I recommend you try them!

Help documentation:

​https://www.php.cn/link/ae502204564aafbffb712be630e3910b​

​https://www.php.cn/link/52130c418d4f02c74f74a5bc1f8020b2​

3. 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.

Ten useful Python utility libraries, I recommend you try them!

Project address:

##​

​https://www.php.cn/link/23ef5cf238a3b88085d95adf94c24a25​

4. JmesPath

Working with JSON in Python is very easy because JSON maps very well to 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:

>>> import jmespath
>>> path = jmespath.search('foo.bar', {'foo': {'bar': 'baz'}})
'baz'
Copy after login

Project address:

​https://www.php.cn/link/ 14b7367a28377d4d513a4d3349861d2f​

5. Simplejson

What’s wrong with the local json module in Python? 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:

Ten useful Python utility libraries, I recommend you try them!

Project address:

​https://www.php.cn/link/3c51419c5607de9699da15be1274b4a6​

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

6. Emoji

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

Ten useful Python utility libraries, I recommend you try them!

project address:

​https://www.php.cn/link/988f9153ac4fd966ea302dd9ab9bae15​

7. 进度条:progress和tqdm

这里有点作弊,因为这是两个包,但忽略其中之一是不公平的。

您可以创建自己的进度条,这也许很有趣,但是使用progress或tqdm程序包更快,更不容易出错。

progress

借助这个软件包,您可以轻松创建进度条:

from progress.bar import Bar
bar = Bar('Processing', max=20)
for i in range(20):
# Do some work
bar.next()
bar.finish()
Copy after login

tqdm

tqdm的功能大致相同,但似乎是最新的。

from tqdm import tqdm
for i in tqdm(range(10000)):
...
Copy after login

以gif动画形式进行一些演示:

Ten useful Python utility libraries, I recommend you try them!

8. Homeassistant

home assistant是一个运行在python 3上的家庭自动化平台。它能够在家里对所有设备进行跟踪和控制,为自动化控制提供了一个平台。

Ten useful Python utility libraries, I recommend you try them!

它现在控制着我们房屋的大部分。我使用Home Assistant将房子中的所有系统捆绑在一起。尽管它确实是一个完整的应用程序,但是您也可以将其安装为Python PyPI软件包。

  • 大多数灯具都是自动化的,百叶窗也是如此。
  • 监视我们的天然气用量,电力用量和产量(太阳能电池板)。
  • 可以跟踪大多数电话的位置,并在进入一个区域时开始操作,例如当我回家时打开车库灯。
  • 它还可以控制我们所有的娱乐系统,例如三星电视和Sonos扬声器。
  • 它能够自动发现网络上的大多数设备,因此上手起来非常容易。  

   项目地址:

​https://www.php.cn/link/16002f7a455a94aa4e91cc34ebdb9f2d​

9. Python-dateutil

python-dateutil模块提供了对标准datetime模块的强大扩展。

您可以使用此库做很多很棒的事情。比如计算相对增量(下个月,明年,下周一,该月的最后一周等)和两个给定日期对象之间的相对增量。

项目地址:

​https://www.php.cn/link/a35d11c2f995c60b0341a9c777f1ae03​

10. Pygame

Pygame 是一组用来开发游戏软件的 Python 程序模块,基于 SDL 库的基础上开发。

Ten useful Python utility libraries, I recommend you try them!

允许你在 Python 程序中创建功能丰富的游戏和多媒体程序,旨在提供对以下内容的低级接口:

  • 音频
  • 键盘
  • 鼠标
  • 游戏杆
  • 基于OpenGL和Direct3D的图形硬件

Pygame具有高度的可移植性,几乎可以在所有平台和操作。

The above is the detailed content of Ten useful Python utility libraries, I recommend you try them!. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:51cto.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template