Files

TODO - Python API

  1. Requirements
  2. Getting started with the app
    1. Configure the code
    2. Set up and activate a virtual environment
    3. Install packages
    4. Run the app

Requirements

This sample was created using the following techologies and they must be installed before proceeding.

Getting started with the app

Configure the code

Configure the MariaDB connection by adding an .env file to the project within the root folder.

Example implementation:

DB_HOST=<host_address>
DB_PORT=<port_number>
DB_USER=<username>
DB_PASS=<password>
DB_NAME=todo

Configuring db.js

The environmental variables from .env are used within tasks.py for the MariaDB Python Connector connection configuration settings:

config = {
    'host': os.getenv("DB_HOST"),
    'port': int(os.getenv("DB_PORT")),
    'user': os.getenv("DB_USER"),
    'password': os.getenv("DB_PASS"),
    'database': os.getenv("DB_NAME")
}

Configuring .env and tasks.py for the MariaDB cloud database service SkySQL

Note: MariaDB SkySQL requires SSL additions to connection. Details coming soon!

Set up and activate a virtual environment

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, youll need to activate it. Activating a virtual environment will put the virtual environment-specific python and pip executables into your shells PATH.

Activate the virtual environment using the following command:

$ . venv/bin/activate activate

Install packages

Flask is a micro web framework written in Python. It is classified as a microframework because it does not require particular tools or libraries.

TL;DR It's what this app uses for the API.

This app also uses the MariaDB Python Connector to connect to and communicate with MariaDB databases.

Install the necessary packages.

$ pip3 install flask mariadb python-dotenv

Run the app

Once you've pulled down the code and have verified that all of the required packages are installed you're ready to run the application!

  1. Execute the following CLI command to start the Python Flask API
$ python3 api.py

The following steps also exist within the "Build and run" section of the root README, and are for startin the React.js project once this API project has been started.

  1. Navigate to the ../../client folder and execute the following CLI command to start the React.js application.
$ npm start
  1. Open a browser window and navigate to http://localhost:3000.