This application is designed to serve as a self-contained backend service providing a non-linear multi-dimensional equation solver.
- a computer running Linux, WSL for Windows or Unix for MacOS
- terminal access to a bash shell
- Python 3.7.x
- Pipenv (python isolated environment)
- Sqlite3 (database)
Install dependencies for building Python 3.7.x source
$ sudo apt update -y $ sudo apt install -y software-properties-common $ sudo add-apt-repository ppa:deadsnakes/ppa $ sudo apt install python3.7
Verify installation
$ python3.7 --version Python 3.7.3
Install Pipenv
$ sudo -H pip3 install pipenv
Install
$ sudo apt install sqlite3
Verify installation
$ sqlite3 --version 3.22.0 2018-01-22 18:45:57 0c55d179733b46d8d0ba4d88e01a25e10677046ee3da1d5b1581e86726f2alt1 # or something like
!#### Installation Complete
- Install Windows Subsystem for Linux using these instructions
- Follow the instructions for Ubuntu/Debian Linux above
For MacOS users install using Homebrew instead of apt
Install Python
$ brew doctor $ brew install python3
Verify installation
$ python3 --version Python 3.7.0
Install Sqlite
$ brew install sqlite3
Verify installation
$ sqlite3 --version 3.22.0 2018-01-22 18:45:57 0c55d179733b46d8d0ba4d88e01a25e10677046ee3da1d5b1581e86726f2alt1 # or something like
Let's activate an isolated virtual environment and install all required python dependencies:
$ pipenv shell --python 3.7 (myapi) $
Note the (myapi) added to the bash prompt above indicates this shell is now in an isolated virtual environment with all requiremensts from the Pipfile installed.
To run all tests located in the tests/ directory
$ pytest
The main entry point for administrating the application is the manager app manage.py
Access manage.py help
$ ./manage.py
The app does not have a database so let's create a database called db.sqlite in the current directory.
$ ./manage createdb
The database is now initialized with the columns and tables required by the app but there is no data.
Let's add some sample data:
$ ./manage.py seed_db
Now let's see an inventory of all urls exposed by the api:
$ ./manage.py show-urls
Now the database contains two models each with multiple equations. Let's open a shell to interact with our data
$ ./manage.py shell
We now have a python shell which includes access to the app context and database
from myapi.models import db, Model, Equation, Variable
all_models = Model.query.all() print(all_models)
for model in all_models: equations = Equation.query.filter(Equation.model_id == model.id) print(30*'') print(model.name) print(equations) print(30'*')
exit()
To run the development server on localhost port 5000
$ ./manage runserver
And poke http://localhost:5000/model with GET/POST/PUT/DELETE requests with json data as follows:
- Add a new model
endpoint: /model method: POST json = {"name": "Unique Model Name"}
- List all models in db
endpoint: /model method: GET
- Get a model by id
endpoint: /model/ method: GET
- Update a model by id
endpoint: /model/ method: PUT json = {"name": "New Model Name"}
- Delete a model
endpoint: /model/ method: DELETE
- Add equation to a model
endpoint: /model/ method: POST json = {"text": "the equation string", "status": "True"}
- Update an equation for a model
endpoint: /model/<model_id>/<equation_id> method: PUT json = {"text": "updated equation string"}
- Delete an equation for a model
** Send a request to update the equation for a model and submit an empty string as text.
All code in MyAPI and Eq is licensed under the GNU AGPLv3 license. See License.txt for details.