10 Python libraries that Everyone who uses Python should Know

Want to know why Python has been so successful? Just look at the large number of libraries that Python provides, both native and third-party. With so many Python libraries, though, it’s not surprising that some don’t get the attention they deserve. Moreover, people who work only in one field do not know what is good in another field or what useful value can be produced in other fields.

Here’s a list of 10 Python libraries that you might have overlooked, but are definitely worth paying attention to. These tools simplify everything from file system access, database programming, and cloud services to building lightweight Web applications, creating GUIs, graphics tools, Excel and Word files, and more. Some libraries are well known, others less so, but all of these Python libraries deserve a place in your toolbox.

1. Arrow

Arrow: Makes it easier for you to handle dates and times.

Why use Arrow: Remember the date calculation we talked about earlier? It was actually a simple calculation tutorial, thinking, what if we wanted to switch time zones, how about more flexible date formatting? Even with a tool as good as Python, if you only use native libraries, you can struggle for a while. Now we have a better option: Arrow.

Arrow has four advantages. First, the arrow is an alternative to Python’s Datetime module, which means that public function calls like.now() and.utcnow() work fine. Second, Arrow provides some common methods, such as switching time zones. Third, Arrow provides “human-friendly” date/time information, such as the ability to effortlessly say what happened “an hour ago” or “two hours from now” (as we talked about in the summer balance). Fourth, Arrow can easily localize date/time information.

Here are three examples of Arrow’s use:

import arrow 
Example 1: Get the current timestamp
t = arrow.utcnow()
print(t.timestamp) # 1566128587

Example 2: Get the current time and format it as a string
t = arrow.now()
s1 = t.format()
print(s1) # 2019-08-18 19:43:07 + 08:00
s2 = t.format("YYYY-MM-DD")
print(s2) # 2019-08-18

Example 3: Turn the string to Arrow and format it into a string of other formats
t = arrow.get("The 2019-12-31 11:30"."YYYY-MM-DD HH:mm")
s3 = t.format('YYYYMMDD')
print(s3) # 20191231
Copy the code

2. Behold

Powerful code debuggingtool.

If you just use print to debug your project, you’ll find that this doesn’t work on large projects! Because the flow of data in a large project is so complex that you have to track the flow of a variable, you might be embarrassed to write a print every few sentences. It has search, filter, sort capabilities, and shows the flow of data across modules.

Suggested reading official example: behold. Readthedocs. IO/en/latest/r…

3. Black

Black: Formats Python code with strict rules.

Black is an uncompromising formatting tool that can detect code styles that do not conform to the specification and format them directly for you. It does not need to be determined by yourself. It is very suitable for people who have a bad code style to correct themselves.

pip install black

Then again, enter CMD/Terminal into your Python files folder and type:

Black your file name.py

Can format the code in the file.

4. Bottle

Bottle: Lightweight website/API development tool.

When you want to build a fast RESTful API or use the basic framework of a Web framework to build an application, Bottle is just fine. Routing, templates, request and response, support for many request protocols, and even advanced features like WebSockets are supported. Again, the amount of work required to start up is minimal, and when more advanced features are needed, the Bottle scales well and excellently.

5. Click

Click: Lets you quickly build command line interfaces for Python applications.

How do we get user input before we use Click? Is it val = input(XXX)? It’s also very simple, but it can be a hassle when you want to set default values for it, but click saves that hassle:

import click
@click.option('--count', default=1, help='Number of greetings')
@click.option('--name', prompt='Your name is'.help='User name'My God, this is a gift to Python programmers. More features, please read the official documentation (https://click-docs-zh-cn.readthedocs.io/zh/latest/), such as it can also set the input parameters:  import click @click.command() @click.option('--count', default=1, help='Number of welcomes.')
@click.option('--name', prompt='Your name is'.help='User name')
def hello(count, name):
    """Welcome user name count times."""
    for x in range(count):
        click.echo('Hello %s! ' % name)

if __name__ == '__main__':
    hello()
Copy the code

The results

6. Nuitka

Nuitka: compiles Python to C++ level executables.

Focus is C++ level application, fast! Fast speed! Fast speed! While Cython can also compile Python to C, Cython focuses only on mathematical and statistical applications, Nuitka can compile to C as-is using any Python program, producing a single-file executable. It’s still early days, but one can imagine how brilliant its future could be

7. Numba

Numba: Selectively speeds up mathematical calculations.

We knew Numpy worked by encapsulating high-speed C libraries in Python interfaces, and Cython compiled certain user-selected types into C, but we found that none of these things worked very well, and it felt like “destiny” was out of my hands. With Numba, we can speed up functions and all you have to do is put a decorator on top of the function, which is really nice:

@nb.jit(nopython=True) def acc(x):

8. Openpyxl

Openpyxl: Read, write, and manipulateExcelFile.

Remember our calendar article? We used the OpenPyXL library in that article. In essence, it is not the only library that can be used to manipulate Excel, but it has some unique features, such as writing the latest file format, XLSX, and there is no limit to the size of files. XLWT is pretty much dead for those two features. Of course, it is not faster than XLWT, which requires you to weigh the use

9. Peewee

Peewee: Small ORM support for SQLite, Mysql and PostgreSQL (easy to write data)library).

This is the first ORM I’ve worked with on Python, and it’s not for everyone, but for those who don’t want to get into SQL statement development, it’s a gem. Peewee is very easy to build, connect to, manipulate databases, and has a lot of query manipulation capabilities built in. Note, however, that PeeWee 3.x is not fully compatible with older versions.

10. PyFilesystem

PyFilesystem: Simplifies the processing of files and directories and supports operations on any file system, greatly improving programming efficiency.

Have you ever had to worry about opening a file that doesn’t exist in a folder (new), making sure that there is a file in a directory, making sure that there is a directory, and of course if you are familiar with OS and IO modules, you will find these things so easy. But for those of you who are not familiar with the statements in these two modules, you may want to Google them. Fortunately, our programming lives are now much happier with PyFilesystem. It supports any file system operation and provides many useful functions, such as viewing files in the current directory:

from fs import open_fs
my_fs = open_fs('. ')
print(my_fs.listdir('/')) 
Copy the code

Displays the directory structure tree

from fs import open_fs
my_fs = open_fs('. ')
my_fs.tree()
Copy the code

Of course, there are more features, please read the official documentation.


Python Dict.com Is more than a dictatorial model