ardydedase / flask-postgres-api

Flask API with Postgres Database. Built from cookiecutter: https://github.com/ardydedase/cookiecutter-flask-postgres-api

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Flask Postgres API

CI

Deploy to Render

Run locally with docker

Use docker-compose

docker-compose up

Run the flask app outside docker

Bring up the Postgres DB container

docker-compose up -d db

Install requirements. mypy takes some time to install

pip install -r requirements.txt

Initialise environment variables. The .env is used in docker-compose.yml.

export FLASK_APP="src/main.py"
export POSTGRES_URL="127.0.0.1:5432"
export POSTGRES_DB="mydb"
export POSTGRES_USER="postgres"
export POSTGRES_PASSWORD="example"

Run migrations

chmod+x run-migrations.sh
./run-migrations.sh

Run flask

# initialise environment variables
flask run

Run tests

py.test -vv

Run with gunicorn

For production.

cd src && gunicorn main:app

Build and run commands in render.com

Build command

pip install -r requirements.txt && ./run-migrations.sh

Run the app

cd src && gunicorn main:app

About

Flask API with Postgres Database. Built from cookiecutter: https://github.com/ardydedase/cookiecutter-flask-postgres-api

License:MIT License


Languages

Language:Python 91.7%Language:Mako 4.4%Language:Dockerfile 3.3%Language:Shell 0.5%