Configuration of Project Environment
This is an API that manages a list of teachers using Python3, Flask, and SQLAlchemy.
Overview on How to Run this API
- Either install a Python IDE or create a Python virtual environment to install the packages required
- Install packages required
- Install MySQL 5.7
- Install Postman extension in Chrome or install curl
Setup procedure
A. Configure project environment (Either A. Install Pycharm OR B. Create a Virtual Environment)
- Install Pycharm (www.jetbrains.com/pycharm/download/)
Open the Teacher API Directory (File -> Open)
- Configure the Base Project Interpreter (File -> Settings -> Project Interpreter)
- Base Project Interpreter: pyenv version 3.6.2 ('path to .pyenv version 3.6.2'/bin/python)
- (pyenv was installed before creating the new project through 'pyenv install 3.6.3')
Note
In my case, when I tried to use the suggested base interpreter set by Pycharm, installing packages only appeared to be successful according to the response message, but the packages do not appear in the package list and modules imported from them do not get resolved. Thus, I resorted to the pyenv.
Manually install packages to project interpreter (Pycharm -> Preferences -> Project -> Project Interpreter -> plus button on the lower left side of the package table) and apply changes OR type the command below on the activated virtual environment.
pip install -r requirements.txt
- Create a Python Virtual Environment
Install virtualenv:
sudo pip install virtualenv
Create virtialenv:
virtualenv -p python3 <name of virtualenv>
Install requirements:
pip install -r requirements.txt
B. Install MySQL
Search on the web on how to install MySQL in your OS
- Create database through piping
mysql -u root < <Path to file>/create_db.sql
- NOTE: depending on your mysql config, you need to provide your password if you have one
C. Initialize and Populate Company Database
- Edit line 14 of teacherAPI/database.py and use the correct url to your mysql
- In my case, I'm using the root and has a password of 'password'
'mysql://root:<password>@localhost/Teacher'
- Either (i) run the line below or (ii) Use the python interactive shell and run the lines below
$ sh database_populator.sh
$python
>>> from teacherAPI.database import init_db; >>> init_db(); >>> from teacherAPI.populate import populate; >>> populate()
D. Run app.py
python app.py
E. Refer to TeacherAPI/controller.py on how to test the code through curl
Endpoints of the Teacher API
- Insert a new teacher record
- Update an existing teacher record
- Delete teacher record
- Get teacher record details
- List all teacher records
- Filter list of teachers using wildcard search
Documentation
- Checkout my Medium Article to learn how to document this repo using Sphinx.
- Swagger is also another great option to document your API's