This sample was created using the following techologies and they must be installed before proceeding.
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=places
Connection details
The environmental variables from .env
are used to connect to the MariaDB using the MariaDB Python Connector configuration pool 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!
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 .
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
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.
$ ./venv/pip3 install python-dotenv flask mariadb
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!
- 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.
- Navigate to the ../../client folder and execute the following CLI command to start the React.js application.
$ npm start
- Open a browser window and navigate to http://localhost:3000.