taiyeoguns / flask-api-trial

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

flask-api-trial API

Flask API Trial

Requirements

  • Python 3.9
  • Docker (for development)
  • Postgres

Installation

Clone Project

git clone https://github.com/taiyeoguns/flask-api-trial.git

Install Requirements

With a virtualenv already set-up, install the requirements with pip:

pip install -r requirements-dev.txt

Install pre-commit

pre-commit install

Add details in .env file

Create .env file from example file and maintain necessary details in it.

cp .env.example .env

Set up database

We use sqlalchemy to model the data and alembic to keep the db up-to-date.

To setup a local db, fill in database details in .env file from earlier or set up environment variables. Ensure the database and user defined in .env is already created in postgres.

For initial database setup, run the following commands:

flask db upgrade

Subsequently, after making any changes to the database models, run the following commands:

flask db migrate
flask db upgrade

Run the application

Activate the virtual environment and start the application by running:

python run.py

or

flask run

API should be available at http://localhost:5000

API documentation should also be available at http://localhost:5000/v1/docs. (For other API versions, change v1 as appropriate)

Tests

In command prompt, run:

pytest -vv

Run application with Docker

Ensure database details are added to .env file from earlier.

The following environment variables should be set in the .env file even if they do not 'exist', the docker postgres image will use them for setting up the container - POSTGRES_USER, POSTGRES_PASSWORD, POSTGRES_DB

With Docker and Docker Compose set up, run:

docker-compose up

Wait till setup is complete and all containers are started.

In another terminal tab/window, run:

docker-compose exec flask_service flask db upgrade

Thereafter, application should be available at http://localhost:5000

About


Languages

Language:Python 85.5%Language:Dockerfile 7.0%Language:Makefile 4.5%Language:Mako 2.7%Language:Shell 0.3%