Welcome back to the third course in the Python scripting for DevOps specialization. In this module we want to think about database libraries. Databases are a form of persistence, that are very good at handling facts. Things like we call as tuples often. Things like people and purchases, and items available for purchase, that sort of thing, like Amazon has, for example. Now database libraries, are sets of code you can use to access databases. By the time you're done with this module, I want you to be able do several things. One is describe different database libraries available to Python. You should also be able to develop scripts that utilize database libraries to query data. You should be able to develop scripts that utilize database libraries to update data, in these databases. All right. Let's start out on lesson 1, and think about available libraries. There are two forms of databases we'll think about here. Relational databases, and relational databases stored data and tables that are joined back together using something called SQL, Structured Query Language. These have been around since the late '60s. They are very popular. They're very good at, a standard way of storing facts, and writing queries to retrieve those facts, and writing code to update those facts. There's many out there. There's MySQL or MariaDB. MariaDB is basically a fork of MySQL. PostgreSQL, SQL Server from Microsoft. Oracle is a big player in the enterprise, and IBM's DB2. There's others out there, but Python has libraries for all of these. There's also no SQL databases. These came around in the last decade or so. They essentially store semi-structured data. They may or may not have a query language. The term MySQL doesn't necessarily mean there's not a structured query language. They often have some derivative query language, but they're not standardized. They really were designed for the semi-structured data, that would be distributed in there. There's many out there. Python has libraries for lots of them, and the big ones are MongoDB. There's Apache CouchDB, or IBM Cloudant. IBM is essentially has a service that hosts CouchDB and the call it Cloudant, and Redis. You'll hear these out there. We can access any. I'm going to look at MySQL and I'm going to look at MongoDB, because those are the two of the most popular ones out there for Python. To start off, we want to first think about how do we install these libraries? There's a package installer called PIP. We're going to talk about PIP in a future course in more detail. But essentially PIP makes it easy to install a third party Python libraries. Based on your installation, sometimes PIP is going to be called PIP. Sometimes it's PIP three. By default, PIP is installed with all later versions of Python. Here I've got two commands in front of you. One is to install what's called the MySQL connector. So you say Python -m pip install MySQL -connector -Python, that's going to install the database library, that has the code, that we can connect to a MySQL database. Below that I have the installer for pymongo. This is the library of talk to a MongoDB. Very similar. A library is essentially just code in a module like you've already seen, you could write yourself. But these are well tested libraries that access these databases. Now when I say they're well tested, not all libraries available in PIP are as well tested as these two. I chose these two, because they're well-documented, and well-tested ways of talking to databases. Here's some sample code that's going to use the MySQL connector to connect to a MySQL database. Basically, I use the import statement, and each library has a specific import. Here it's MySQL.connector. Now I've got access to use that connector class, and I'm going to call the method connect. I'm going to pass it in the location of the MySQL database, my username and password. It's going to return a variable, which is a class of type MySQL connector. Here's a similar example where we import pymongo, and we're going to call the MongoClient class, passing in the location of our MongoDB. That's going to return a client, and that client, I can then access like a list to retrieve a specific database. Then I've got a variable that's the database of the Mongo. Now we'll look at this further in future lessons. That's enough for this lesson. A little review here is, relational database is stored data in tables, and we'll issue SQL through Python, to access that data, and create new facts. No SQL databases have non standard query methods, and we can use those from Python. PIP allows us to easily install third-party Python libraries. Again, we'll explore that in more detail later on. All right. See you in next lesson.