Giter VIP home page Giter VIP logo

mariadb-developers / todo-app-python Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 2.0 204 KB

TODO is a simple web application that introduces you to the power, performance, and simplicity of MariaDB. The TODO app contains a React.js front-end and Python back-end, which utilizes the MariaDB Python connector

License: MIT License

Python 100.00%
mariadb mariadb-database mariadb-skysql python python3 python-driver mariadb-python mariadb-connector tutorial

todo-app-python's Introduction

TODO

TODO is a web application that introduces you to the power, performance, and simplicity of MariaDB.

This application is made of two parts:

  • Client
    • web UI that communicates with REST endpoints available through an API app (see below).
    • is a React.js project located in the client folder.
  • API

This README will walk you through the steps for getting the TODO web application up and running using MariaDB.

Table of Contents

  1. Requirements
  2. Getting started with MariaDB
  3. Get the code
  4. Create the database and table
  5. Configure, build and run the apps
    1. Configure
    2. Create and activate a Python virtual environment
    3. Install Python packages
    4. Build and run the Python API app
    5. Build and run the Client app
  6. Support and contribution
  7. License

Requirements

This sample application requires the following to be installed/enabled on your machine:

1.) Getting Started with MariaDB

MariaDB is a community-developed, commercially supported relational database management system, and the database you'll be using for this application.

If you don't have a MariaDB database up and running you can find more information on how to download, install and start using a MariaDB database in the MariaDB Quickstart Guide.

2.) Get the code

First, use git (through CLI or a client) to retrieve the code using git clone:

$ git clone https://github.com/mariadb-developers/todo-app-python.git

Next, because this repo uses a git submodule, you will need to pull the client application using:

$ git submodule update --init --recursive

3.) Create the database and table

Connect to your MariaDB database (from Step #2) and execute the following SQL scripts using the following options:

a.) Use the MariaDB command-line client to execute the SQL contained within schema.sql.

Example command:

$ mariadb --host HOST_ADDRESS --port PORT_NO --user USER --password PASSWORD < schema.sql

OR

b.) Copy, paste and execute the raw SQL commands contained in schema.sql using a client of your choice.

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)
);

4.) Configure, Build and Run the Apps

This application is made of two parts:

  • Client
    • web UI that communicates with REST endpoints available through an API app (see below).
    • is a React.js project located in the client (/src/client) folder.
  • API

The following steps, a through e, will walk you through the process of configuring, building and running the api and client applications.

a.) Configure the app

Configure the MariaDB connection by adding an .env file to the project within the api 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 src/api/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!

b.) Create and activate a Python 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 (within /src/api):

$ 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 (within /src/api):

$ . venv/bin/activate activate

c.) Install Python 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 by executing the following command (within /src/api):

$ pip3 install flask mariadb python-dotenv

d.) Build and run the Python API 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!

From /src/api execute the following CLI command to start the the Python project:

$ python3 api.py

Note: You will need to use seperate terminals for the client and api apps.

e.) Build and run the UI (Client) app

Once the API project is running you can now communicate with the exposed endpoints directly (via HTTP requests) or with the application UI, which is contained with the client folder of this repo.

To start the client application follow the instructions here.

Support and Contribution

Please feel free to submit PR's, issues or requests to this project project directly.

If you have any other questions, comments, or looking for more information on MariaDB please check out:

Or reach out to us diretly via:

License

License

todo-app-python's People

Contributors

rhedgpeth avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.