Master These 22 Python Packages for Success

Source: Internet

Translated from: Produced | CSDN (ID: CSDNnews)

The following is the translation:

What is the current usage status of Python across various industries worldwide?

This question is the reason I wrote this article. I have identified 22 of the most commonly used Python packages, hoping to provide you with some inspiration.

First, I listed the highest downloaded Python packages on PyPI in the past year. Let’s take a look at the functions of these packages, their relationships, and why they are so popular.

1. Urllib3

893 million downloads

Urllib3 is a Python HTTP client that provides many features not available in the standard Python library.

  • Thread-safe

  • Connection pooling

  • Client-side SSL/TLS verification

  • File uploads with multipart encoding

  • Helper functions for request retries and handling HTTP redirects

  • Support for gzip and deflate encoding

  • Support for HTTP and SOCKS proxies

Despite its name, Urllib3 is not a successor to Python’s built-in urllib2. If you want to use Python’s core functionality as much as possible (for example, due to installation restrictions), you can look at urllib.request.

For end users, I strongly recommend the requests package (refer to item six in the list). Urllib3 ranks first because nearly 1200 packages depend on it, many of which are also high on the list.

2. Six

732 million downloads

Six is a compatibility tool for Python 2 and Python 3. The goal of the project is to allow code to run on both Python 2 and Python 3.

It provides many functions that abstract away the syntax differences between Python 2 and Python 3. The easiest example to understand is six.print_(). In Python 3, you need to use the print() function for output, while in Python 2, print is used without parentheses. Therefore, using six.print_() supports both languages simultaneously.

Key points:

  • The name of the package, six, comes from 2 x 3 = 6

  • Similar libraries include future

  • If you want to convert code to Python 3 (while no longer supporting Python 2), you can look at 2to3

While I understand why this package is so popular, I still hope people will abandon Python 2 as soon as possible, especially since official support for Python 2 ended on January 1, 2020.

3. botocore, boto3, s3transfer, awscli

These projects are discussed together:

  • botocore: 3rd place, 660 million downloads

  • s3transfer: 7th place, 584 million downloads

  • awscli: 17th place, 394 million downloads

  • boto3: 22nd place, 329 million downloads

Botocore is the underlying interface for AWS. Botocore is the foundation for the boto3 library (22nd place), which allows you to access Amazon’s S3, EC2, and other services.

Botocore is also the foundation for AWS-CLI, which is the command-line interface for AWS.

s3transfer (7th place) is a Python library for managing S3 transfers. This library is still under development, and its homepage does not recommend using it, or at least suggests fixing the version, as its API may change even between minor versions. Boto3, AWS-CLI, and many other projects depend on s3transfer.

The high ranking of AWS-related libraries indicates how popular AWS services are.

4. Pip

627 million downloadsdownloads

I guess many people know and love pip (the package installer for Python). Using pip to install packages from the Python Package Index and other repositories (such as local mirrors or custom repositories containing private software) is effortless.

Fun facts about pip:

  • The name Pip is a recursive definition: Pip Installs Packages

  • Pip is very easy to use. Installing a package only requires executing pip install <package_name>. Deleting it only requires executing pip uninstall <package_name>.

  • The biggest advantage of pip is that it can install a range of packages, usually listed in a requirements.txt file. This file can also specify detailed version numbers for each package. Most Python projects include this file.

  • When used in conjunction with virtualenv (57th place), pip can create predictable, isolated environments without interfering with the system’s environment.

5. python-dateutil

617 million downloads

The python-dateutil module provides powerful extensions to the standard datetime module. Things that the standard Python datetime cannot do can be accomplished using python-dateutil.

This library can accomplish many very cool features. I will just give one very useful example: fuzzy parsing of date strings from 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:01

6. requests

611 million downloads

Requests is based on the top downloaded library urllib3. With it, sending requests becomes extremely simple. Many people prefer requests over urllib3, so the number of end users for requests may even exceed that of urllib3. The latter is more low-level and typically appears as a dependency for other projects.

The following example demonstrates how easy it is to use requests:

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'{

Leave a Comment