Code Monkey home page Code Monkey logo

cookiecutter-flask-postgres-api's Introduction

CI

Cookiecutter for Flask API with Postgres

Project template for Flask API.

Medium post: A useful template to help you spin up your next project and start building.

What's included

  • Go live with a Continuous Deployment Pipeline using GitHub and Render's Infrastructure as Code. See sample IaC file here.
  • Works with SQLAlchemy / Postgres DB out of the box.
  • Uses mypy for static type checks.

Reference app

There is a sample reference package generated from our cookiecutter which you can refer to in here: https://github.com/ardydedase/flask-postgres-api.

Deploy the Sample Repo built from this cookiecutter to Render.com:

  • Check the deployed API: <API URL>/healthcheck
  • Ensure that you have deleted your resources from Render when you're done.

Usage

  1. Install cookiecutter

     pip install cookiecutter
    
  2. Cookie cut the template.

     cookiecutter [email protected]:ardydedase/cookiecutter-flask-postgres-api.git
    
  3. Enter the values accordingly. Pick your project name.

  4. Change the working directory to the generated folder, same name as the project slug.

     cd <project_slug>
    

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

โš ๏ธ For Mac users: Make sure you run brew install postgresql. Stackoverflow

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 app:app

cookiecutter-flask-postgres-api's People

Contributors

ardydedase 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  avatar  avatar

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.