Giter Club home page Giter Club logo

bootstrap-python-backend's Introduction

Bootstrap Python Backend

A template repository for backend Python REST API server with a database

Stack: Flask Server, Gunicorn WSGI, Postgres DB, Docker, Shell

Prerequisites

Setup

Setup and activate a virtual environment (optional but recommended)

pip install -r requirements.txt

Testing

# Run unit tests with PyTest
python setup.py test

Running

Running Flask Server Locally

# Install application
python setup.py install

# Start server locally
sh scripts/start_server.sh

To start server locally with custom settings:

  • Number of workers
  • Threads per worker
  • Worker timeout
  • Gunicorn log level
sh scripts/start_server.sh workers=3 threads=2 timeout=30 log-level=DEBUG

Running Flask Server inside Docker

# Build docker image
python setup.py build_docker

# Start server
sh scripts/run_docker.sh

For custom settings, update Dockerfile before building image

Running Flask Server with Postgres DB

Runs the entire setup using docker-compose:

  • Flask API server
  • Postgres database
  • Postgres admin

Make sure you have DATA_DIR environment variable set. This directory will be used as persistent volume mount for Postgres database.

# Start all services (will always create new backend-api image)
sh scripts/run_all.sh

# Use existing backend-api image as per the VERSION file
sh scripts/run_all.sh false

# Stop all services
sh scripts/stop_all.sh

This will start three containers on the same virtual network. Database will run on port5432, admin console will be available on http://localhost:5433 and API server will be available on http://localhost:8000

Endpoints

# Health check
curl localhost:8000/health

# Sample POST endpoint
curl -X POST http://localhost:8000/postendpoint -H 'Content-Type: application/json' -d '{"param": "value"}'

Kubernetes

To run the app on a Kubernetes cluster:

  • Install kubernetes-cli (kubectl)
  • Build and push the docker image to a registry accessible on the cluster
  • Replace the placeholders in the deployment files under kubernetes directory and run the following commands
kubectl apply -f kubernetes/deployment.yaml
kubectl apply -f kubernetes/service.yaml

bootstrap-python-backend's People

Contributors

jaymindesai avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Forkers

archtaqi

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.