Wednesday, July 22, 2020

Real Python: Python Packages: Five Real Python Favorites

Python has a vast ecosystem of packages, modules, and libraries that you can use to create your application. Some of these packages and modules are included with your Python installation and are collectively known as the standard library.

The standard library consists of modules that provide standardized solutions to common programming problems. They’re great building blocks for applications across many disciplines. However, many developers prefer to use alternative packages, or extensions, that may improve on the usability and usefulness of what’s in the standard library.

In this tutorial, you’ll meet some of the authors at Real Python and learn about packages they like to use in place of more common packages in the standard library.

The packages you’ll learn about in this tutorial are:

  • pudb: An advanced, text-based visual debugger
  • requests: A beautiful API for making HTTP requests
  • parse: An intuitive, readable text matcher
  • dateutil: An extension for the popular datetime library
  • typer: An intuitive command-line interface parser

You’ll begin by looking at a visual and powerful alternative to pdb.

Free Download: Get a sample chapter from Python Tricks: The Book that shows you Python's best practices with simple examples you can apply instantly to write more beautiful + Pythonic code.

pudb for Visual Debugging

Christopher Trudeau

Christopher Trudeau is an author and course creator at Real Python. At work he’s a consultant who helps organizations improve their technical teams. At home, he spends his time with board games and photography.

I spend a lot of time working SSHed into remote machines, so I can’t take advantage of most IDEs. My debugger of choice is pudb, which has a text-based user interface. I find its interface intuitive and easy to use.

Python ships with pdb, which was inspired by gdb, which itself was inspired by dbx. While pdb does the job, the strongest thing it has going for it is that it ships with Python. Because it’s based on the command line, you have to remember a lot of shortcut keys and can only see small amounts of the source code at a time.

An alternative Python package for debugging is pudb. It displays a full screen of source code along with useful debugging information. It has the added benefit of making me feel nostalgic for the old days when I coded in Turbo Pascal:

Pudb Interface

The interface is divided into two main parts. The left panel is for source code, and the right panel is for context information. The right-hand side is subdivided into three sections:

  1. Variables
  2. Stack
  3. Breakpoints

Everything you need in a debugger is available on one screen.

Interacting With pudb

You can install pudb through pip:

$ python -m pip install pudb

If you’re using Python 3.7 or above, then you can take advantage of breakpoint() by setting the PYTHONBREAKPOINT environment variable to pudb.set_trace. If you’re using a Unix-based operating system such as Linux or macOS, then you set the variable as follows:

$ export PYTHONBREAKPOINT=pudb.set_trace

If you’re based in Windows, the command is different:

C:\> set PYTHONBREAKPOINT=pudb.set_trace

Alternatively, you can insert import pudb; pudb.set_trace() directly into your code.

Read the full article at https://realpython.com/python-packages/ »


[ Improve Your Python With 🐍 Python Tricks 💌 – Get a short & sweet Python Trick delivered to your inbox every couple of days. >> Click here to learn more and see examples ]



from Planet Python
via read more

No comments:

Post a Comment

TestDriven.io: Working with Static and Media Files in Django

This article looks at how to work with static and media files in a Django project, locally and in production. from Planet Python via read...