python导入外部包_您会喜欢的10个外部Python软件包

python导入外部包

by Adam Goldschmidt

亚当·戈德施密特(Adam Goldschmidt)

您会喜欢的10个外部Python软件包 (10 External Python packages you are going to love)

Python is an experiment in how much freedom programmers need. Too much freedom and nobody can read another’s code; too little and expressiveness is endangered. - Guido van Rossum
Python是程序员需要多少自由度的实验。 太多的自由,没人能读懂别人的密码。 太少,表现力受到威胁。 -Guido van Rossum

This freedom that Guido talks about is part of what makes Python so popular. That popularity, among other, is what attracts more and more developers to use the language - eventually leading to some really amazing open source projects.

Guido谈论的这种自由是使Python如此受欢迎的部分原因。 这种受欢迎程度尤其吸引了越来越多的开发人员使用该语言-最终导致了一些非常出色的开源项目。

I usually find myself project hunting on GitHub once a day. Throughout this article, I will try to cover 10 wonderful packages that you may or may not be familiar with. I will start from the less trendy and end up with… well, Flask.

我通常每天发现自己在GitHub上进行一次项目狩猎。 在本文中,我将尝试介绍您可能熟悉或可能不熟悉的10个出色的程序包。 我将从比较不流行的事物开始,最后以…好吧,Flask。

让我们开始! (Let’s begin!)

Loguru-轻松记录 (Loguru — Logging made easy)

This is a really awesome package I regularly use in my projects. It describes itself as “a library which aims to bring enjoyable logging in Python”. This package just lets you easily configure your logs out of the box.

这是我在项目中经常使用的非常棒的软件包。 它将自己描述为“一个旨在以Python带来令人愉悦的日志记录的库”。 该软件包使您可以轻松地开箱即用地配置日志。

All you have to do after installing is to import the module:

安装后您要做的就是导入模块:

from loguru import logger

And you’re free to use it out of the box:

您可以随意使用它:

logger.debug("Hello, cool debugger")

The documentation is good and there are many customization options.

该文档很好,并且有许多自定义选项。

更多工具 (more-itertools)

A variety of interesting methods that could sometimes come very useful, such as peekable:

有时可能会变得非常有用的多种有趣方法,例如peekable

>>> p = peekable(['a', 'b'])>>> p.peek()'a'>>> next(p)'a'

or chunked:

chunked

>>> list(chunked([1, 2, 3, 4, 5, 6], 3))[[1, 2, 3], [4, 5, 6]]

MonkeyType —静态类型注释生成器 (MonkeyType — Static type annotations generator)

monkeytype run myscript.py

This package automatically generates type annotations for you, either in a stub file or in the source code itself, by collecting runtime types. Right, Python doesn’t enforce you to use annotations — but I believe they are very important for readability of the code (and sometimes for avoiding errors), which is also why there are 2 more packages in this list that are handling type annotations :)

该程序包通过收集运行时类型,在存根文件或源代码本身中自动为您生成类型注释。 是的,Python不会强迫您使用注释-但我认为它们对于代码的可读性(有时是避免错误)非常重要,这也是为什么此列表中还有2个处理类型注释的软件包的原因: )

Pyright —静态类型检查器 (Pyright — Static type checker)

Exciting new package coming from Microsoft. The inital commit was just 17 days ago! This package is the competitor of Mypy (also on this list). To be honest, I haven’t yet had the chance to use it, but I definitely plan to. I currently use mypy as a type checker, but I’ll give this one a try!

令人兴奋的Microsoft新软件包。 最初的提交只是17天前! 该软件包是Mypy的竞争对手(也在此列表中)。 老实说,我还没有机会使用它,但是我绝对打算。 我目前将mypy用作类型检查器,但我将尝试一下!

请求-异步 -支持async / await语法requests (requests-async — support for async/await syntax for requests)

This is a new package I discovered the other day on GitHub, and it seems pretty promising. We all know the requests package, that lets us easily handle HTTP requests in our code. Well, this package implements async and await words for these requests:

这是我前几天在GitHub上发现的一个新程序包,看起来很有希望。 我们都知道请求包,它使我们可以轻松地在代码中处理HTTP请求。 好了,这个包为这些请求实现了asyncawait字:

import requests_async as requests​response = await requests.get('https://example.org')print(response.status_code)print(response.text)

Pretty cool right?

很酷吧?

HTTPie —现代命令行cURL (HTTPie — Modern command line cURL)

Those of you who have used cURL before, must know it’s not that fun. Having to remember the parameters names, making sure your data is encapsulated… Well, HTTPie aims to make this much easier. Here’s one of their examples, of submitting form data:

那些以前使用过cURL的人必须知道它不是那么有趣。 必须记住参数名称,以确保您的数据被封装了……好吧,HTTPie旨在简化这一过程。 这是他们提交表单数据的示例之一:

http -f POST example.org hello=World

pipenv —更好的Python包装 (pipenv — Better packaging for Python)

When I start a new project, I always create a new virtualenv and install some basic packages with pip. I then need to save these packages names in a file, be it setup.py or requirements.txt. Those of you who have worked with npm, know it's much simpler there. All you need to do is write npm —save and the package name is saved in your package.json. That's why I first created pypkgfreeze, a simple package to "freeze" the versions of your currently used pip packages into setup.py.

当我开始一个新项目时,我总是创建一个新的virtualenv并使用pip安装一些基本软件包。 然后,我需要将这些软件包的名称保存在一个文件中,无论是setup.py还是requirements.txt 。 那些使用npm工作过的人知道,那里的操作要简单得多。 您需要做的就是写npm —save ,包名称保存在package.json 。 这就是为什么我首先创建pypkgfreeze的原因,这是一个简单的程序包,用于将当前使用的pip程序包的版本“冻结”到setup.py

Anyway, pipenv is an interesting solution that aims to merge the two worlds - They describe it best in their repo page:

无论如何,pipenv是一个有趣的解决方案,旨在合并两个世界-他们在回购页面中对其进行了最佳描述:

It automatically creates and manages a virtualenv for your projects, as well as adds/removes packages from your Pipfile as you install/uninstall packages. It also generates the ever-important Pipfile.lock, which is used to produce deterministic builds.

它会为您的项目自动创建和管理virtualenv,并在您安装/卸载软件包时从Pipfile添加/删除软件包。 它还会生成非常重要的Pipfile.lock ,用于生成确定性的构建。

You can try it out here.

您可以在这里尝试。

mypy —静态类型检查器 (mypy — Static type checker)

As I said before, this is the package I currently use as my standard static type checker. It helps me keep my code readable and elegant (I think).

如前所述,这是我目前用作标准静态类型检查器的软件包。 它可以帮助我保持代码的可读性和优美性(我认为)。

黑色 (black)

I have tried many Python formatters, and black is clearly my favourite. The syntax looks neat, and the command line runs quick and can either check the files or actually edit them - very useful for CI/CD. You can even try it here!

我尝试了许多Python格式化程序,而black显然是我的最爱。 语法看起来很整洁,命令行运行很快,可以检查文件或实际编辑它们-对于CI / CD很有用。 您甚至可以在这里尝试!

烧瓶 (flask)

Not sure if I have anything to write here that hasn’t been written before. You are probably familiar with this astonishing micro framework, and if you’re not.. you definitely should check it out.

不知道我是否有什么要写的,以前没有写过。 您可能熟悉这个令人惊讶的微型框架,如果不熟悉,那么您肯定应该检查一下。

你走之前… (Before you go…)

Thanks for reading! You can follow my GitHub account for more cool repos. I tend to star every cool thing that I see :)

谢谢阅读! 您可以关注我的GitHub帐户以获得更多很棒的存储库。 我倾向于盯着我看到的每件很酷的东西:)

If you enjoyed this article, please hold down the clap button ? to help others find it. The longer you hold it, the more claps you give!

如果您喜欢这篇文章,请按住拍手按钮? 帮助别人找到它。 握的时间越长,拍手就越多!

And do not hesitate to share your thoughts in the comments below.

并且不要在下面的评论中分享您的想法。

翻译自: https://www.freecodecamp.org/news/these-python-packages-will-help-accelerate-your-development-process-d4b3f170b1ea/

python导入外部包

你可能感兴趣的:(python导入外部包_您会喜欢的10个外部Python软件包)