Is Python suitable for database applications

Python and databases

Python offers the use of database management systems (DBMS) very easily. In the following, the term database system is used instead of the awkward word. What is the advantage of a database system?

We thereby separate data from the program and do not have to worry about:

  • the storage of the data
  • the management of the data

We simply transfer our data to our database and then we can then use our program to determine what should happen with the data. Most of the time you want to evaluate them in some form or just output them. Whereby a selection takes place during the output so that only the data that is currently required is displayed.

Concrete example that we are implementing step by step

How does that look in a specific example?

We want program a birthday warning that saves its data in a database. For this we need the first name, last name and the date of the birthday. If you like, you can also include your phone number and e-mail in the data. In the first step, it must be possible to enter and save the data using a form.

This data can be searched.

In addition, the data can be output with the desired sorting order, e.g. by first name or surname or date of birth.

And the next 3 birthdays should always be displayed as a candy when the program starts. So here we have a selection of the data according to a certain criterion and a sorted output.

And last but not least, we want to be able to change data again (typing errors occur) and delete it (you don't want to congratulate some people on their birthday anymore).

About the function. What does Python offer us when it comes to databases?

Different database systems

With Python we can use different database systems like MySQL, SQLite, Oracle, PostgreSQL and other databases.

Data can be managed very easily via a database system. This includes:

  • Create records
  • Delete records
  • change data
  • Find data
  • Sort data

In the following chapter we want to work with SQLite. This variant is an optimal introduction to the topic of databases. The basic programming is the same for all databases. The advantage of SQLite is that it already exists as a module in Python and is embedded directly as a file in the software project. If you want to look in the file system - it is a ".db" file.

The big advantage for beginners is: We don't have to install a client-server database, as is the case with MySQL, for example. In this way, the application with the database and data that has already been recorded can be passed on very easily.

But step by step.

Our learning application for database usage

In the following, we want to program the “Birthday Warner” application that manages birthdays. We use the following data fields for this:

  • First name
  • Surname
  • birthday

The following actions are available:

  • Create data record
  • Show
  • to change
  • Clear
  • search
  • sort by

We will do this step by step in the following chapters and learn how to use databases in Python.

Recommend • Social Bookmarks • Thank you