你应该了解的Python模块

jopen 6年前

最好的Python模块集合。Python是美丽的。因此,利用这些模块保持你的代码清洁,可维护。

Modules

  • Docopt. Forget optparse and argparse, and build beautiful, readable and (if you need) complex command-line interfaces using docstrings. IMO the best module created in 2013.

  • Requests, or HTTP for humans, is a more pythonic approach to deal with HTTP requests. Much, much, much better than urllib2. And it has been downloaded over 5,000,000 times from PyPI for a reason :)

  • lxml is a binding for libxml2 and libxslt. If you are dealing with XML or HMTL, lxml is the best solution. Full stop.

  • Bottle is a fast, simple and lightweight WSGI micro web-framework. Build small websites and REST APIs in seconds. All the framework is just one py file that you can drop in your directory.

  • sh is a full-fledged subprocess interface for Python that allows you to call any program as if it were a function. Super handy.

  • Structlog is advanced processor for logging. It integrates with any existing logger, wrapping the Python standard library. You can build custom loggers, adding context as you go, to keep your logs consistent and readable.

  • Watchdog is cross platform Python library and shell utilities to monitor file system events. Super handy and easy to use.

  • Delorean lets you play with dates and times in a very convenient way. Set time zones, truncate to seconds, minutes, hours, or even iterate from one date to another using a specific step. Check out the doc, it contains plenty of examples.

Bonus track

  • PEW. I discovered this project only one month ago, and I felt in love. PEW is a set of tools to manage multiple virtual environments. Works flawlessly on bash, zsh, fish and powershell. Give it a try.

  • antigravity. Run a Python shell (>=2.7) and type import antigravity.