Code Monkey home page Code Monkey logo

tutorial_simpleteacherapi's Introduction

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

  1. Either install a Python IDE or create a Python virtual environment to install the packages required
  2. Install packages required
  3. Install MySQL 5.7
  4. Install Postman extension in Chrome or install curl

Setup procedure

A. Configure project environment (Either A. Install Pycharm OR B. Create a Virtual Environment)

  1. 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
  2. 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

  1. Search on the web on how to install MySQL in your OS
  2. 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

  1. 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'

  2. Either (i) run the line below or (ii) Use the python interactive shell and run the lines below
    1. $ sh database_populator.sh
    2. $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

  1. Insert a new teacher record
  2. Update an existing teacher record
  3. Delete teacher record
  4. Get teacher record details
  5. List all teacher records
  6. 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

tutorial_simpleteacherapi's People

Contributors

richdayandnight avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

tutorial_simpleteacherapi's Issues

Problem on windows system

Hi,
I am trying to learn Sphinx, and using your tutorial. During the setup phase, I got the following

(env) D:\2019\Docs_for_PyOCD\richdaydocs>pip install -r requirements.txt

..... lots of stuff that installed fine , then

Requirement already satisfied: colorama>=0.3.5; sys_platform == "win32" in d:\2019\docs_for_pyocd\env\lib\site-packages (from Sphinx==1.7.5->-r requirements.txt (line 29)) (0.4.1)
Building wheels for collected packages: CommonMark, itsdangerous, MarkupSafe, mysqlclient, purepng, SQLAlchemy
  Building wheel for CommonMark (setup.py) ... done
  Stored in directory: C:\Users\Philip Freidin\AppData\Local\pip\Cache\wheels\a0\f4\35\019d917f6875107ade3aad634c982f5c6b604c5631cddf20ac
  Building wheel for itsdangerous (setup.py) ... done
  Stored in directory: C:\Users\Philip Freidin\AppData\Local\pip\Cache\wheels\2c\4a\61\5599631c1554768c6290b08c02c72d7317910374ca602ff1e5
  Building wheel for MarkupSafe (setup.py) ... done
  Stored in directory: C:\Users\Philip Freidin\AppData\Local\pip\Cache\wheels\33\56\20\ebe49a5c612fffe1c5a632146b16596f9e64676768661e4e46
  Building wheel for mysqlclient (setup.py) ... error
  ERROR: Complete output from command 'd:\2019\docs_for_pyocd\env\scripts\python.exe' -u -c 'import setuptools, tokenize;__file__='"'"'D:\\temp\\pip-install-7oklcxee\\mysqlclient\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d 'D:\temp\pip-wheel-kwb2vz71' --python-tag cp37:
  ERROR: running bdist_wheel
  running build
  running build_py
  creating build
  creating build\lib.win-amd64-3.7
  copying _mysql_exceptions.py -> build\lib.win-amd64-3.7
  creating build\lib.win-amd64-3.7\MySQLdb
  copying MySQLdb\__init__.py -> build\lib.win-amd64-3.7\MySQLdb
  copying MySQLdb\compat.py -> build\lib.win-amd64-3.7\MySQLdb
  copying MySQLdb\connections.py -> build\lib.win-amd64-3.7\MySQLdb
  copying MySQLdb\converters.py -> build\lib.win-amd64-3.7\MySQLdb
  copying MySQLdb\cursors.py -> build\lib.win-amd64-3.7\MySQLdb
  copying MySQLdb\release.py -> build\lib.win-amd64-3.7\MySQLdb
  copying MySQLdb\times.py -> build\lib.win-amd64-3.7\MySQLdb
  creating build\lib.win-amd64-3.7\MySQLdb\constants
  copying MySQLdb\constants\__init__.py -> build\lib.win-amd64-3.7\MySQLdb\constants
  copying MySQLdb\constants\CLIENT.py -> build\lib.win-amd64-3.7\MySQLdb\constants
  copying MySQLdb\constants\CR.py -> build\lib.win-amd64-3.7\MySQLdb\constants
  copying MySQLdb\constants\ER.py -> build\lib.win-amd64-3.7\MySQLdb\constants
  copying MySQLdb\constants\FIELD_TYPE.py -> build\lib.win-amd64-3.7\MySQLdb\constants
  copying MySQLdb\constants\FLAG.py -> build\lib.win-amd64-3.7\MySQLdb\constants
  copying MySQLdb\constants\REFRESH.py -> build\lib.win-amd64-3.7\MySQLdb\constants
  running build_ext
  building '_mysql' extension
  creating build\temp.win-amd64-3.7
  creating build\temp.win-amd64-3.7\Release
  C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\bin\HostX86\x64\cl.exe /c /nologo /Ox /W3 /GL /DNDEBUG /MD -Dversion_info=(1,3,12,'final',0) -D__version__=1.3.12 "-IC:\Program Files (x86)\MySQL\MySQL Connector C 6.1\include" -Ic:\uac_ok\python37\include -Ic:\uac_ok\python37\include "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\ATLMFC\include" "-IC:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Tools\MSVC\14.16.27023\include" "-IC:\Program Files (x86)\Windows Kits\NETFXSDK\4.6.1\include\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\ucrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\shared" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\um" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\winrt" "-IC:\Program Files (x86)\Windows Kits\10\include\10.0.17763.0\cppwinrt" /Tc_mysql.c /Fobuild\temp.win-amd64-3.7\Release\_mysql.obj /Zl  _mysql.c
  _mysql.c(29): fatal error C1083: Cannot open include file: 'mysql.h': No such file or directory
  error: command 'C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\VC\\Tools\\MSVC\\14.16.27023\\bin\\HostX86\\x64\\cl.exe' failed with exit status 2
  ----------------------------------------
  ERROR: Failed building wheel for mysqlclient
  Running setup.py clean for mysqlclient
  Building wheel for purepng (setup.py) ... done
  Stored in directory: C:\Users\Philip Freidin\AppData\Local\pip\Cache\wheels\c3\1c\f3\f27382debc5b947c2239743b3e82cb9e6aeed3942377a07ae3
  Building wheel for SQLAlchemy (setup.py) ... done
  Stored in directory: C:\Users\Philip Freidin\AppData\Local\pip\Cache\wheels\df\fc\61\df2f43ec3f11f864554bdc006a866a3ffffa59740bcf3674ef
Successfully built CommonMark itsdangerous MarkupSafe purepng SQLAlchemy
Failed to build mysqlclient

So this probably means I would have problems running the actual tutorial project, but I should be fine with the Sphinx stuff that I care about.

FYI, My system is Windows 7 Pro x64

Thanks,
Philip Freidin

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.