Connect to the database and execute the following SQL scripts:
CREATE DATABASE todo;
CREATE TABLE todo.tasks (
id INT(11) unsigned NOT NULL AUTO_INCREMENT,
description VARCHAR(500) NOT NULL,
completed BOOLEAN NOT NULL DEFAULT 0,
PRIMARY KEY (id)
);
Update the configuration in api.py for your target database instance.
config = {
'host': 'host_address',
'user': 'your_user',
'password': 'your_pass',
'database': 'todo'
}
Then save api.py.
A virtual environment is a directory tree which contains Python executable files and other files which indicate that it is a virtual environment. Basically, it's the backbone for running your Python Flask app.
Creation of virtual environments is done by executing the following command:
$ python3 -m venv venv
Tip: Tip: pyvenv is only available in Python 3.4 or later. For older versions please use the virtualenv tool.
Before you can start installing or using packages in your virtual environment, you’ll need to activate it. Activating a virtual environment will put the virtual environment-specific python and pip executables into your shell’s PATH.
Activate the virtual environment using the following command:
$ . venv/bin/activate activate
Open a terminal window and install the MariaDB and Flask modules.
$ pip install mariadb flask
$ python api.py
That's it! You should now having a running Python/Flask API project. You can test HTTP requests targeting http://localhost:8080/api/tasks.