Home > Article > Backend Development > 6 libraries commonly used by Python programmers
When programming, small setbacks can be just as painful as big problems. No one wants to just pop up a message window or quickly write to the database after a lot of effort. Therefore, programmers will appreciate solutions that can handle these problems quickly and are also robust in the long run.
The following 6 Python libraries can quickly solve difficult problems at hand, and can also serve as the basis for large-scale projects.
What is: Pyglet is a cross-platform framework written in pure Python language, used to develop multimedia and window special effects applications.
Why is it needed: Developing the functional modules required for graphical interface applications from scratch is very cumbersome. Pyglet provides a large number of ready-made modules, saving a lot of time: window functions, OpenGL special effects, audio and video playback , keyboard and mouse processing and image processing. (However, Pyglet does not provide UI components such as buttons, toolbars or menus.)
All the above modules are implemented natively under Windows, OS X or Linux platforms and do not rely on external binary packages; it is written in pure Python language. Pyglet is released under the BSD license and can be used in any commercial and open source projects.
What is: Peewee is a small but very powerful library that supports database access through ORM and natively supports databases such as SQLite, MySQL and PostgreSQL.
Why is it needed: Any application that needs to frequently use external data will basically use a database, but reading and writing data from the database through temporary connections will cause a lot of trouble.
Peewee provides a safe and stable channel to access database resources. For Python programmers and database engineers, the Python classes provided by this library will be easy to use. With the support of Peewee, we can access the database quickly and easily, and can be expanded to add more options in the future without redesigning. Peewee also natively supports database transactions and has many optional additional modules that provide functions from database connection pooling to advanced field types like many-to-many.
What is: Bottle is a small, lightweight network development framework that is also very fast.
Why you need it: If you just want to quickly create a Restful API interface, or just want to use a network development framework to make a simple application, Bottle can easily meet your requirements. It has all the features you will need: routing, templates, access to request and response data, support for multiple web servers, and advanced features such as WebSockets.
Creating an application requires very little work, and Bottle is designed with scalability in mind. If you need more advanced features, you can access them at any time.
What is: Simply put, Invoke allows you to easily perform system management tasks through a Python library.
Why you need it: Who doesn’t want a “concise, high-level interface that can run shell commands, define and categorize execution tasks”? It is completely reasonable to use Python to replace ordinary shell scripts and perform corresponding tasks. Invoke provides solutions for performing common command line tasks and managing them. For Invoke, each management task is like a Python function, and more complex tasks can be designed elegantly on this basis.
It should be noted that Invoke is still a preview version; if you want to use a stable tool (even if it is no longer actively developed), you can consider Invoke's predecessor-Fabric.
What is: Splinter is a Python library for automated testing of network applications.
Why you need it: As we all know, there is nothing more boring than automated web application testing. With Splinter, you can automate all operations such as opening a browser, entering a URL, filling in a form, and clicking a button.
Specific browsers require corresponding drivers, but fortunately Chrome and Firefox drivers are already included. In addition, Splinter can also remotely control browsers on other machines through Selenium Remote. You can even manually execute JavaScript code in the target browser.
If you want to know the specifics of a certain browser when browsing a specific website, then Splinter will be a very useful tool. If you want to learn about interacting with websites without relying on a browser, check out Twill. (Translator: Twill is a scripting language that supports users to browse the network through the command line.)
What is: Arrow is a library that can better handle date and time (data/time) in Python.
Why you need it: Dealing with time zones, date conversions, dealing with different date formats, and other date-related stuff is enough to give you a day and a half of headaches. If you use the modules in the standard library that comes with Python, you will probably have a headache for two days.
There are four major benefits to switching to the Arrow library, which are very useful in both the long and short term. First, it can perfectly replace the datetime module in Python, which means you can still use common function call forms like .now() and .utcnow(). Second, it provides methods for common needs such as converting time zones. Third, it provides "human-friendly" date/time information - that is, it can easily tell you whether something happened "one hour ago" or "will happen in two hours" . Fourth, it easily converts date/time information to local time.
The above is the detailed content of 6 libraries commonly used by Python programmers. For more information, please follow other related articles on the PHP Chinese website!