Skip to content

mbcaldeiro/microservices-scaffold

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

microservices-scaffold

Python Microservice Scaffold is an example of how to structure a Flask Microservice Project. This Scaffold is build over PyMS package. PyMS is a Microservice chassis pattern like Spring Boot (Java) or Gizmo (Golang). PyMS is a collection of libraries, best practices and recommended ways to build microservices with Python which handles cross-cutting concerns:

  • Externalized configuration
  • Logging
  • Health checks
  • Metrics
  • Distributed tracing

Python package Build Status Coverage Status Requirements Status Updates Python 3

Table of Contents

How to run the scaffold

Installation

Clone the repository

git clone [email protected]:purwowd/microservices-scaffold.git
cd microservices-scaffold

Install with virtualenv

virtualenv --python=python[3.6|3.7|3.8] venv
source venv/bin/activate
pip install -r requirements.txt

Install with pipenv

pip install pipenv
pipenv install

Install on MacOS

virtualenv -p python3 venv
source venv/bin/activate
pip3 install -r requirements.txt
python manage.py runserver

Advantages over plain pip and requirements.txt

Pipenv generates two files: a Pipfileand a Pipfile.lock.

  • Pipfile: Is a high level declaration of the dependencies of your project. It can contain "dev" dependencies (usually test related stuff) and "standard" dependencies which are the ones you'll need for your project to function
  • Pipfile.lock: Is the "list" of all the dependencies your Pipfile has installed, along with their version and their hashes. This prevents two things: Conflicts between dependencies and installing a malicious module.

For a more in-depth explanation please refer to the official documentation.

Run your python script

python manage.py runserver

Check the result

Your default endpoints will be in this url:

http://127.0.0.1:5000/films
http://127.0.0.1:5000/actors

This URL is set in your config.yml:

pyms:
  config:
    DEBUG: false
    TESTING: false
    APP_NAME: Template
    APPLICATION_ROOT : "" # <!---

You can acceded to a swagger ui in the next url:

http://127.0.0.1:5000/ui/

This PATH is set in your config.yml:

pyms:
  services:
    swagger:
      path: "swagger"
      file: "swagger.yaml"
      url: "/ui/" # <!---

Read more info in the documentation page: https://microservices-scaffold.readthedocs.io/en/latest/

Docker

You can dockerize this microservice with these steps:

  • Create and push the image

    docker build -t films -f Dockerfile .

  • Run the image:

    docker run -d -p 5000:5000 films

Kubernetes

You can run this microservice in a Kubernetes cluster with:

kubectl apply -f service.yaml

How To contribute

We appreciate opening issues and pull requests to make PyMS even more stable & useful! See This doc for more details

About

Barebone Python Microservices with Flask

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Python 90.9%
  • Dockerfile 6.1%
  • Makefile 3.0%