Giter Club home page Giter Club logo

python-flask-rest-microservice's Introduction

Python Flask REST Microservice

REST API written in Python Flask using SQLAlchemy as the ORM with auto migration capabilities

Pre-requisites

 python -m pip install -U pip 
  • Download & Install MySQL Server locally or use an external database (OPTIONAL)

For Developers

  • Download & install NodeJS
  • Install nodemon (use sudo if you in linux)
npm i -g nodemon

Installation

# Clone the repository 
git clone https://github.com/dipayan/python-flask-rest-microservice.git
# Change into the directory
cd python-flask-rest-microservice
# Install all required dependencies with
// skip // pipenv install --deploy --skip-lock
// skip // ('pip' or 'pip3') install psycopg2
pipenv install pylint --dev
# Activate the project virtual environment
pipenv shell
# Create an local .env file and replace with the relevant values
cp .env.sample .env

You can also set the enviroment variables explicity (OPTIONAL)

PORT=9400
BUILD_DEV=development
DATABASE_URL=postgres://name:password@host:port/dbname

Running the application

Start the app

python run.py

Start the app for developers

nodemon run.py

Usage

API Specifications

  • GET: /api/v1/todos/
  • GET: /api/v1/todos/?title=
  • GET: /api/v1/todos/{todo_id}
  • POST: /api/v1/todos/
  • PUT: /api/v1/todos/{todo_id}
  • DELETE: /api/v1/todos/{todo_id}

Example Get all todos curl http://localhost:{PORT}/api/v1/todos/

Running the application as a Docker container

cd python-flask-rest-microservice
# Build the docker image 
docker build -t python-flask-app .
# Run the docker container and put the port as specified in the .env file
docker run -d -p 9000:9000 --name python-flask-app -e PORT=9000 -e BUILD_ENV='development' -e DATABASE_URL='mysql+pymysql://user:pass@host:port/dbname' python-flask-app
# Check the logs
docker logs -f python-flask-app
# Cleaup the container
docker stop python-flask-app && docker rm python-flask-app

Database Auto migration & creation

You can create the tables using the following set of commands

python manage.py db init
python manage.py db migrate
python manage.py db upgrade

Author

Dipayan Biswas

python-flask-rest-microservice's People

Contributors

dipayan avatar donaldmurillo avatar kdubba14 avatar

Watchers

James Cloos 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.