6 Python libraries every programmer will love

Fast, safe database access; quick, clean Web frameworks, no-fuss cross-platform GUIs -- these libraries solve problems over the short term and the long haul

6 Python libraries every programmer will love
Credit: Pixabay

In programming, little frustrations can be as agonizing as the big problems. No one wants to pull their hair out merely to pop up a window with a text message or to write quickly (and safely!) to a database. But programmers would welcome fast solutions to these issues that are also robust in the long run.

Here are six Python libraries that provide quick fixes to immediate problems, but can also be used as the underpinnings for bigger projects.


What it is: Pyglet is cross-platform framework for multimedia and windows graphics in pure Python.

Why you need it: It provides handy access to items that are tedious to implement from scratch for a GUI application: window functions, OpenGL graphics, audio and video playback, keyboard and mouse handling, and working with image files. (It doesn't provide UI widgets like buttons, toolbars, or menus, though.)

All of this is done through the native platform capabilities in Windows, OS X, or Linux, so there are no binary dependencies; it's pure Python. It's also BSD-licensed, so it can be included in any commercial or open source project.


What it is: Peewee is a small but powerful library for accessing databases by way of an ORM, with native support for SQLite, MySQL, and PostgreSQL.

Why you need it: Any application that uses external data in more than a trivial manner typically uses a database, but getting and setting data from a database via ad hoc connection strings is asking for trouble.

Peewee provides a safe, programmatic path to access database resources, using a set of Python classes that are intuitive for both Python developers and database engineers. With Peewee, a quick-and-dirty way to access a database can be later expanded to a more robust option without having to rip it out and start over. Transactions are natively supported, and optional modules provide support for everything from connection pooling to advanced field types like many-to-many.


What it is: Bottle is a tiny, lightweight Web framework that's also quite fast.

Why you need it: When you simply want to throw together a quick RESTful API or use the bare bones of a Web framework to build an app, Bottle gives you no more than you need. Routing, templates, access to request and response data, support for multiple server types from plain old CGI on up, and support for more advanced features like WebSockets -- it's all here.

The amount of work needed to get started is minimal, and Bottle's design is elegantly extensible for when more advanced functions have to be plugged in.


What it is: "Pythonic remote execution" -- in plainer English, Invoke allows you to perform admin tasks using a Python library.

Why you need it: Who wouldn't want a "clean, high-level API for running shell commands and defining/organizing task functions"? Using Python as a replacement for common shell scripting tasks makes sense, and Invoke provides common-sense solutions to take command-line tasks and manage them as if they were Python functions, allowing bigger items to be elegantly built around them.

Note that Invoke's version as of this writing is considered pre-release software; if you want something guaranteed stable (if no longer being actively developed), consider Invoke's predecessor, Fabric.


What it is: Splinter is a Python library for testing Web applications by automating interactions with them.

Why you need it: Let's face it -- little is less fun than trying to automate Web application testing. Splinter automates everything end to end, invoking the browser, passing URLs, filling out forms, clicking buttons, and so on.

It requires drivers to work with a specific browser, but Chrome and Firefox are already covered, and it can use Selenium Remote to control a browser running elsewhere. You can even manually execute JavaScript in the target browser.

Splinter is useful if you want to find out how specific browsers behave when confronted with a given website. For automating site interactions without a browser -- essentially a kind of curl on steroids -- check out Twill.


What it is: The Arrow library sorts out the mess that is Python's date/time handling.

Why you need it: Dealing with time zones, date conversions, date formats, and all the rest are a headache and a half. With Python's standard library for date/time work, you get two headaches.

Arrow provides four big boons, all useful in the short and the long term. One, it's a drop-in replacement for Python's datetime module, meaning common function calls like .now() and .utcnow() work as expected. Two, it provides methods for common needs like shifting or converting timezones. Three, it provides "humanized" date/time information -- such as being able to say something happened "an hour ago" or will happen "in two hours" without a lot of effort. Four, it can localize date/time information without breaking a sweat.

[An earlier version of this article stated incorrectly that the Invoke library could be used to manage systems remotely by SSH.]

From CIO: 8 Free Online Courses to Grow Your Tech Skills
View Comments
Join the discussion
Be the first to comment on this article. Our Commenting Policies