Home > Article > Backend Development > Reduce costs and increase efficiency! 12 must-try Python toolkits!
In this article, I have selected 12 of the most useful software packages to share with you. I believe you will learn something!
Dash is relatively new. It is ideal for building data visualization applications using pure Python, so it is especially suitable for those who work with data. Dash is a hybrid of Flask, Plotly.js and React.js.
#Dash quickly puts the content you want into beautiful dashboards without touching a single line of Javascript.
Pygame is the Python wrapper module of the SDL multimedia library. Simple DirectMedia Layer is a cross-platform development library designed to provide low-level access to OpenGL and Direct3D Pygame's audio keyboard mouse joystick graphics hardware and is highly portable and can run on almost all platforms and operating systems.
It has a complete game engine, and you can also use the library to play MP3 files directly from Python scripts.
Pillow is a fork of the Python image library. 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.
To understand it quickly, this is how to display an image from Python code:
from PIL import Image im = Image.open("kittens.jpg") im.show() print(im.format, im.size, im.mode) # JPEG (1920, 1357) RGB##4, ColoramaUsing Colorama, It's possible to add some color to the terminal:
from colorama import Fore, Back, Style print(Fore.RED + 'some red text') print(Back.GREEN + 'and with a green background') print(Style.DIM + 'and in dim text') print(Style.RESET_ALL) print('back to normal now')The documentation is short and sweet and can be found on the Colorama PyPI page. If you want to use it on Windows as well, you need to call colorama.init() first. 5. JmesPathUsing JSON in Python is very easy because JSON maps very well to Python dictionaries. To me, this is one of its best features.
import jmespath # Get a specific element d = {"foo": {"bar": "baz"}} print(jmespath.search('foo.bar', d)) # baz # Using a wildcard to get all names d = {"foo": {"bar": [{"name": "one"}, {"name": "two"}]}} print(jmespath.search('foo.bar[*].name', d)) # [“one”, “two”]6. RequestsRequests Create one of the most downloaded Python libraries. It makes web requests really simple, yet still very powerful and versatile.
import requests r = requests.get('https://api.github.com/user', auth=('user', 'pass')) r.status_code # 200 r.headers['content-type'] # 'application/json; charset=utf8' r.encoding # 'utf-8' r.text # u'{"type":"User"...' r.json() # {u'disk_usage': 368627, u'private_gists': 484, ...}This is a very basic example, but requests can also do all the advanced stuff, like: Use cookies for authentication
try: import simplejson as json except ImportError: import json
import emoji result = emoji.emojize('Python is :thumbs_up:') print(result) # 'Python is ' # You can also reverse this: result = emoji.demojize('Python is ') print(result) # 'Python is :thumbs_up:'9. Chardet You can use the chardet module to detect the character set of a file or data stream. This is useful, for example, when analyzing large amounts of random text. However, it can also be used when working with remotely downloaded data when you don't know what the character set is. After installing chardet, you have an additional command line tool called chardetect, which can be used like this:
$ chardetect somefile.txt somefile.txt: ascii with confidence 1.010, Python-dateutil The python-dateutil module provides access to the standard datetime module powerful extension. You can do a lot of cool things with this library, such as fuzzing dates in log files.
from dateutil.parser import parse logline = 'INFO 2020-01-01T00:00:01 Happy new year, human.' timestamp = parse(logline, fuzzy=True) print(timestamp) # 2020-01-01 00:00:0111. How to use progress barprogress
from progress.bar import Bar bar = Bar('Processing', max=20) for i in range(20): # Do some work bar.next() bar.finish()tqdm has roughly the same function, but it is the latest. First, some demonstrations in the form of gif animation: 12, IPythonIf you often use interactive programs but don’t know IPython, you should try it out !Some of the features provided by the enhanced IPython shell include:
The above is the detailed content of Reduce costs and increase efficiency! 12 must-try Python toolkits!. For more information, please follow other related articles on the PHP Chinese website!