When we think of libraries the average person probably envisions their local library down the street where they go to check out books. But when you stop to think about a library, you will find that it is a location where information is stored. Authors will write books where people can travel to this data storage, search for any specific information they want, then check that information out and use that piece of information for anything they want. A library in Python is a very similar concept, users will create files containing specific information for other users to import into their programs to perform various tasks. Throughout the course of this report, we will cover what exactly libraries in python are, give some examples of multiple types of libraries including uses, and how exactly a programmer can import and use a library within their own program. We will also go over some of the most common libraries used and some of the lesser-known types of libraries.
What are Python Libraries
As previously mentioned, a library within python is simply a collection of data. To be more specific, a library is a collection of files within Python called “Modules”, most of the modules you find within python are user created since python is an open-source programming language. There are many different types of libraries out in the world of python, with each library having its own specific purpose. For example one would use the library “OpenPyxl” or “Xlwings” to read/write data to Microsoft Excel, create macros for automating processes, or generate graphical user interfaces using python as a means to communicate with excels programming language “VBA”(Visual Basic Analysis). Although Python does have many user-created libraries, it does come with many existing libraries pre-installed when you download Python onto your computer, these are called “Python Standard Libraries”. These libraries have a wide variety of uses that a programmer could utilize in a multitude of situations. For example, one popular standard library is called “NumPy”, this stands for Numerical Python and is mainly used in mathematical computations. Whenever a user designs a program that needs to perform mathematical problem solutions such as machine learning, they use this library. One interesting fact is that libraries can also pull modules from other libraries, such is the case for a library called “TensorFlow”. This library is like NumPy in the aspect of complex mathematical problem-solving and machine learning, but the interesting thing about TensorFlow is that it actually imports modules from NumPy in order to perform some tasks.
Importing and using Libraries
In order for a programmer to use a library in their code they would need to first have that specific library downloaded and installed onto their computer. To do this a user will have to have python already downloaded onto their computer as a basic prerequisite and do one of two options. First, the user would have to open their command prompt and use a tool called “pip”, which is the pre-installed data package managing tool python uses to install new libraries that aren’t a part of the pre-installed python standard library. To install pip to install a library, the user would open their command prompt, and type in the command “py -m pip install” (Figure 1) followed by the name of the library they would want to download.
After this is complete the user would then have to open whatever IDE they plan to use and then proceed to import either that entire library into their program or segments of it known as modules (Figure 2) into their program. I personally tend to only download certain modules I need within that library. You can see in Figure 2 that I opened my PyCharm IDE and have imported the library “OpenPyxl” and a specific module within that library called “openpyxl.cell”.
The second method to install and import libraries within python would be to simply just do it through your IDE, in this scenario it is PyCharm specific. A user would open their IDE, type “import” followed by the name of the of the library you would like to import. If the library is installed onto the user’s computer already it will simply just import the library. But if the user doesn’t have the library installed prior, PyCharm will highlight the segment of text in red prompting the programmer to right click on it and select “install package” (Figure 3).
In this scenario you can see that I have gone into my PyCharm editor and typed in the command “Import Xlwings”, I did not have this library installed prior to this so the section of code was highlighted red. I then right clicked on the red highlight, and it is now prompting me to install that package.
Common Python Libraries
Two of the most common python libraries that have been widely popularized due to the easy-to-use artificial intelligence interfaces are known as Keras and Pytorch. Both of these libraries specialize in the creation of machine learning and artificial intelligence. They both utilize a series of large datasets and neural networks to help the AI learn and grow. A neural network is named after the human brain; this is because a neural network actually mimics the functionality of how neurons are fired within the human brain. At its heart, a neural network is a cluster of “nodes” that contain inputs, a setpoint, and an output, all nodes are intertwined together, and each node won’t activate unless the adjacent nodes setpoint triggers it to activate. theses libraries are simply popular because they are easy to use while creating these node datasets. Of the two Keras is the most popular option, Keras offers a more plug-and-play method of programming that newer programmers find less intimidating. This also allows for programs to be created, compiled, and executed faster than if programmed using Pytorch. Another feature that draws newer programmers to Keras is the fact that models within Keras are easier to export and manipulate, this saves time when initially developing the program you want to create. Pytorch on the other hand is more popular with more experienced programmers due to it being able to work with larger datasets and having more extensive debugging capabilities that make it easier for developers to go back and fix any errors they may find at a later time. Below is an example video on how exactly a user would set up and use tools within Keras.
Keras Library How-To Video
Lesser-Known Python Libraries
So far, we have covered what a generic definition of a library is within Python, how to install and use some of these libraries, and what some of the most common types of libraries are within Python. Now we will move on to some of the lesser-known libraries in Python, what their uses are, and how they could be just as useful as some of their more popular counterparts. One lesser-known python module is one called Tabulate. Tabulate is a library that allows users to manipulate tabular datasets within python. A tabular dataset could be a data frame, a list of lists or dictionaries, or even a dictionary itself. The interesting thing about tabulate is that it doesn’t manipulate the values of the data itself but rather manipulates the way in which the data is formatted. Tabulate presents all of the data in the form of a table! This makes presenting the data easier for the user to read and understand what is happening within the data. Here is an example of a neatly formatted tabulate table presenting a list of animals.
- — — — — — — — — — — — — — — — — — — — — — — — -
Jadzia Domestic Short Hair Female Stray
Gonzo German Shepherd Dog/Mix Male Stray
Maggie Shep Mix/Siberian Husky Female Stray
Pretty Girl Domestic Short Hair Female Stray
Pretty Girl Domestic Short Hair Female Stray
— — — — — — — — — — — — — — — — — — — — — — — -
Another lesser-known library is one called Numerizer, this library is used in order to generate text-based numerical entries within a table or data set into an actual integer or float data types. For example, if one were to type out the word seven, then use Numerizer, the library would read and decode that word and spit out an output of “7”. This could be useful if a programmer was developing and commissioning a sort and search program. Lastly, we have a library that could add a little bit of fun to a developer’s program called Emoji. Emoji is a library in Python that allows the developer to insert fun emoji images into the program that they are creating. This could be used in various types of games one would develop in python, maybe a programmer would like to give players a fun Easter egg within the game or add a bit of flare at the end of the game for a winning player or even assign different emoji images to identify different players within a game. Below is an example of what it would look like for a programmer to use Emoji to add emoji’s to a python program. Below is a how-to guide on how to use the Emoji Library in Python for further clarification.
Emoji How-To Video
Emoji Code Example
We have learned an in-depth description of what libraries in python are. We have learned two ways to install libraries onto our computer to use in our programming: one using pip install and the other using the install tools directly built into PyCharm. We have also seen some images showing some uses of modules within Python. We have also gone over some of the most common libraries contained within Python such as Keras, Pytorch, Numpy, and TensorFlow to name a few. We have also covered some of the not-so-common libraries within python such as Tabulate for formatting data into tables for easier presentation, Numerizer which is used to convert string data types into integer or float point data types for search functions, and emoji which is a library used for fun more than it is for work, this library allows programmers to insert popular and fun emoji images into a program. Every library has its place and specific use, some libraries are similar to one another and some are very original but each one is no less useful than the other.